2015-07-20 97 views
0

无法登录,这是我的代码,大约XMPP登录XMPP可以登录iOS上的模拟器,但在iPhone上

- (void)connect{ 
    if (self.xmppStream == nil) { 
     self.xmppStream = [[XMPPStream alloc] init]; 
     [self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()]; 

    } 

    if (![self.xmppStream isConnected]) { 
     XMPPJID *jid = [XMPPJID jidWithUser:_userName.text domain:@"kwjdemacbook-pro.local" resource:nil]; 
     [self.xmppStream setMyJID:jid]; 
     [self.xmppStream setHostName:@"192.168.16.74"]; 
     NSError *error = nil; 
     if (![self.xmppStream connectWithTimeout:20.0 error:&error]) { 
      NSLog(@"connect Error:%@",[[error userInfo] description]); 
     } 
    } 
} 

- (void)xmppStreamDidConnect:(XMPPStream *)sender{ 
    NSError *error = nil; 
    if (![self.xmppStream authenticateWithPassword:@"123456" error:&error]) { 
     NSLog(@"Authenticate Error:%@",[[error userInfo] description]); 
    } 
} 

XMPP可以登陆iOS上的模拟器和发送mesage但iPhone无法登录。

+0

我的电脑的IP:192.168.16.74掩码:255.255.255.0我的iPhone连接我的电脑wifi和我的iphone IP :192.168.2.4 –

+0

我改变[self.xmppStream setHostName:@“192.168.2.1”];结果相同 –

+1

您确定您的iPhone与本地Mac服务器位于同一网络吗?你确定Mac的端口没有被防火墙阻止吗?这看起来像是一个网络配置问题。 –

回答

0

我想你错过设置端口号XMPPStream,

试试这个,

- (void)connect{ 
    if (self.xmppStream == nil) { 
     self.xmppStream = [[XMPPStream alloc] init]; 
     [self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()]; 

    } 

    if (![self.xmppStream isConnected]) { 
     XMPPJID *jid = [XMPPJID jidWithUser:_userName.text domain:@"kwjdemacbook-pro.local" resource:nil]; 
     [self.xmppStream setMyJID:jid]; 
     [self.xmppStream setHostName:@"192.168.16.74"]; 

    // setPort number of your openfire server 
[self.xmppStream setHostPort:5222]; 
     NSError *error = nil; 
     if (![self.xmppStream connectWithTimeout:20.0 error:&error]) { 
      NSLog(@"connect Error:%@",[[error userInfo] description]); 
     } 
    } 
} 
+0

我曾尝试过,但无法连接上iphone –

相关问题