无法使用用户名和密码登录以在 Xmpp 中聊天

Not able to login with username and password for chat in Xmpp

我正在尝试使用 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>

请高人指导解决此问题。

谢谢。

您需要在登录时发送完整的 jabber id:

 NSString *jabberID = @"test12";

应该是这样的

  NSString *jabberID = @"test12@yourdomain.com";

如果您在本地主机上工作,它应该如下所示:

 NSString *jabberID = @"test12@localhost";

你似乎得到 not-authorized 因为你 jabberID 类型。它必须看起来像电子邮件,不仅是登录部分,还有域。

尝试使用:

*jabberID = @"test12@my.domain";