我正在尝试使用Xmpp Framework实现聊天我已成功导入框架并且我已连接服务器也问题是我无法登录我在服务器中创建的用户名和密码。我正在使用Open Fire进行xmpp聊天,我已经创建了用户,但我无法登录。
我的代码
- (void)setupStream {
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
xmppStream.hostName=@"Hostname";
//xmppStream.hostPort=5222;
}
- (void)goOnline {
XMPPPresence *presence = [XMPPPresence presence];
[[self xmppStream] sendElement:presence];
}
- (void)goOffline {
XMPPPresence *presence = [XMPPPresence presenceWithType:@"unavailable"];
[[self xmppStream] sendElement:presence];
}
- (void)disconnect {
[self goOffline];
[xmppStream disconnect];
}
- (BOOL)connect {
[self setupStream];
NSString *jabberID = @"test12";
NSString *myPassword = @"1234567";
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];
return NO;
}
else
{
NSLog(@"Connection success");
return YES;
}
return YES;
}
xmppStream代码
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
NSError *error = nil;
[[self xmppStream] authenticateWithPassword:@"1234567" error:&error];
}
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender {
[self goOnline];
}
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq {
return NO;
}
我已经完成了上面的代码我得到连接seccuss但用户无法登录即时通讯。
Connection success
<?xml version='1.0'?>
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='app.umeetup.com'>
<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="app.umeetup.com" id="9da175a8" stream1:lang="en" version="1.0"/>
RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
SEND: <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5"/>
RECV: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09ImFwcC51bWVldHVwLmNvbSIsbm9uY2U9IjBSYm13alFDRkplVHNBQXhXdm9DekppQXg2aUM1aXRiYmZHMERiV0QiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>
SEND: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9InRlc3QxMiIscmVhbG09ImFwcC51bWVldHVwLmNvbSIsbm9uY2U9IjBSYm13alFDRkplVHNBQXhXdm9DekppQXg2aUM1aXRiYmZHMERiV0QiLGNub25jZT0iQzNEQzc2NTAtRTREOS00QTBGLUEzQjQtNUEzM0NBQzZEQzBFIixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL2FwcC51bWVldHVwLmNvbSIscmVzcG9uc2U9ZjEyNjgxN2ViYWIxZGExZGY5ZmE5MmVjMmNjY2QwYjgsY2hhcnNldD11dGYtOA==</response>
RECV: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
请有人指导解决此问题。
感谢。
答案 0 :(得分:1)
您需要在登录时发送整个jabber id:
NSString *jabberID = @"test12";
这应该是这样的
NSString *jabberID = @"test12@yourdomain.com";
如果您正在使用localhost,则应如下所示:
NSString *jabberID = @"test12@localhost";
答案 1 :(得分:0)
您似乎因为 jabberID 类型而获得not-authorized
。它看起来像电子邮件,不仅是登录部分,还包括域名。
尝试使用:
*jabberID = @"test12@my.domain";