我想在iOS中使用xmpp框架以匿名方式連接到openfire服務器。通過提供JID和PW,我可以連接到開火。但是,當我嘗試匿名連接時,它說「服務器不支持匿名身份驗證」。在iOS中使用XMPP框架進行匿名身份驗證
我在xib文件中使用了一個按鈕。當其低於點擊代碼執行:
- (IBAction)login:(id)sender {
[[self appDelegate]connect];
NSError *authenticationError = nil;
[self.xmppStream authenticateAnonymously:&authenticationError];
}
和下面是用於連接方法的代碼:
- (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;
}