XMPP可以在iOS模拟器上登录但无法在iphone上登录

时间:2015-07-20 13:54:49

标签: ios iphone xmpp

这是我的代码,关于xmpp login

- (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模拟器上登录并发送消息,但无法在iphone上登录。

1 个答案:

答案 0 :(得分: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]);
        }
    }
}