【发布时间】:2014-05-03 12:25:16
【问题描述】:
我想在 iOS 中使用 xmpp 框架匿名连接到 openfire 服务器。我可以通过提供 JID 和 PW 来连接到 open fire。但是,当我尝试匿名连接时,它显示“服务器不支持匿名身份验证”。
我正在使用 xib 文件中的按钮。当它点击下面的代码执行时:
- (IBAction)login:(id)sender {
[[self appDelegate]connect];
NSError *authenticationError = nil;
[self.xmppStream authenticateAnonymously:&authenticationError];
}
下面是connect方法的代码:
- (BOOL)connect {
[self setupStream];
xmppStream.hostName = @"abc.xyz.com";
//xmppStream.hostName = @"Virtuals-MacBook-Pro.local ";
NSString *jabberID = [[NSUserDefaults standardUserDefaults] stringForKey:@"userID"];
NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:@"userPassword"];
if (![xmppStream isDisconnected]) {
return YES;
}
if (jabberID == nil || myPassword == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
//[alertView release];
return NO;
}
return YES;
}
【问题讨论】:
标签: ios xmpp xcode5 xmppframework