iOS:XMPPFramework:无法使用gmail帐户登录

时间:2016-01-06 07:25:16

标签: ios objective-c xmppframework

我正在使用robbiehanson中的XMPPFramework开发一个简单的聊天应用程序。我在我的系统中安装了 eJabberd 服务器并创建了一些用户。我设置 hostname =“localhost”并尝试使用该用户凭据登录。它已成功登录。当我更改主机名时,即 hostname =“talk.google.com”。我无法登录。我“登录尝试被阻止”邮件和

<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized></not-authorized></failure>

FYI,

- (BOOL)connectWithUsername:(NSString*)username WithPassword:(NSString*)pwd
{
    if (![xmppStream isDisconnected]) {
        return YES;
    }

   // NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyJID];
    //NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword];
    NSString* myJID=username;
    NSString* myPassword=pwd;
    //
    // If you don't want to use the Settings view to set the JID,
    // uncomment the section below to hard code a JID and password.
    //
    // Replace me with the proper JID and password:
    //  myJID = @"user@gmail.com/xmppframework";
    //  myPassword = @"";

    if (myJID == nil || myPassword == nil) {
        NSLog(@"JID and password must be set before connecting!");

        return NO;
    }

    [xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
    password = myPassword;

    NSError *error = nil;
    if (![xmppStream connectWithTimeout:100 error:&error])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error connecting"
                                                             message:@"See console for error details."
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];

        NSLog(@"Error connecting: %@", error);

        return NO;
    }


    [self goOnline];

    return YES;
}

我需要在Google Developer Console中注册应用吗? 请向我提供在XMPPFramework中集成Gmail帐户的解决方案。

1 个答案:

答案 0 :(得分:0)

您确定已正确设置JID和主机名吗?

XMPPXOAuth2Google.m文件中的goOnline文件中有一些说明。

您还应该知道XMPP上的Google服务器配置有所不同,请确保所需的配置在XMPPFramework文件内以及代理内的- (void)goOnline { XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit NSString *domain = [xmppStream.myJID domain]; //Google set their presence priority to 24, so we do the same to be compatible. if([domain isEqualToString:@"gmail.com"] || [domain isEqualToString:@"gtalk.com"] || [domain isEqualToString:@"talk.google.com"]) { NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" stringValue:@"24"]; [presence addChild:priority]; } [[self xmppStream] sendElement:presence]; } 方法内完成。

某些默认更改由{{1}}完成:

{{1}}
相关问题