[英]iOS:XMPPFramework: Cant able to login using gmail account
我正在使用robbiehanson的XMPPFramework开发一个简单的聊天应用程序。 我在我的系统中安装了eJabberd服务器并创建了一些用户。 我设置hostname =“localhost”并尝试使用该用户凭据登录。 它已成功登录。当我更改主机名即hostname =“talk.google.com”时 。 我无法登录。 我收到了“登录尝试被阻止”的邮件和
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized></not-authorized></failure>
仅供参考,
- (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帐户的解决方案。
您确定已正确设置JID和主机名吗?
在hostname
属性上方的XMPPStream.h
文件中有一些指令。
您还应该知道XMPP上的Google服务器配置有所不同,请确保所需的配置在XMPPXOAuth2Google.m
文件中完成,并且也在委托内的goOnline
方法内goOnline
。
一些默认更改由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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.