Mug*_*diq 5 xmpp ios xmppframework xcode5
我想在iOS中使用xmpp框架匿名连接到openfire服务器.我可以通过提供JID和PW连接到开火.但是,当我尝试匿名连接时,它说"服务器不支持匿名身份验证".
我在xib文件中使用了一个按钮.当点击下面的代码时执行:
- (IBAction)login:(id)sender {
[[self appDelegate]connect];
NSError *authenticationError = nil;
[self.xmppStream authenticateAnonymously:&authenticationError];
}
Run Code Online (Sandbox Code Playgroud)
以下是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;
}
Run Code Online (Sandbox Code Playgroud)
匿名身份验证的步骤:
1-首先连接xmpp-stream,然后匿名进行身份验证.
[[self xmppStream] authenticateAnonymously:&error];
Run Code Online (Sandbox Code Playgroud)
那么你将被匿名认证.但是一件非常重要的事情.在进行身份验证之前,获取已注册用户的用户名和密码并连接到xmpp-stream
| 归档时间: |
|
| 查看次数: |
1097 次 |
| 最近记录: |