XMPP可以在iOS模拟器上登录但不能在iphone上登录
Posted
技术标签:
【中文标题】XMPP可以在iOS模拟器上登录但不能在iphone上登录【英文标题】:XMPP can login on iOS simulator but can't login on iphone 【发布时间】:2015-07-20 13:54:48 【问题描述】:这是我的代码,关于 xmpp 登录
- (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上登录。
【问题讨论】:
我的电脑ip : 192.168.16.74 mask:255.255.255.0 我的iphone 连接我的电脑wifi 和我的iphone ip:192.168.2.4 我改变 [self.xmppStream setHostName:@"192.168.2.1"];结果相同 您确定您的 iPhone 与您的本地 Mac 服务器在同一个网络上吗?您确定 Mac 的端口没有被防火墙阻止吗?这对我来说似乎是一个网络配置问题。 【参考方案1】:我认为您错过了为 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]);
【讨论】:
我试过了,但无法在 iphone 上连接以上是关于XMPP可以在iOS模拟器上登录但不能在iphone上登录的主要内容,如果未能解决你的问题,请参考以下文章
XMPP 聊天服务器未在 iOS 设备上连接。在模拟器上完美工作
UIWebView pich 可以在 iPhone 5.0 模拟器上进行缩放,但不能在 iPhone 4.3 和 iPad 4.3、5.0 模拟器上工作?
在ios模拟器上成功构建skia,但无法在我的iphone上运行