iphone - 使用 xmpp 框架时未调用委托(delegate)方法

标签 iphone ios xmppframework

我正在使用 xcode 4.5 从这个 link.am 下载示例项目 http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-interface-setup/

无法编译。缺少框架。所以我从 此链接... https://github.com/robbiehanson/XMPPFramework ...最终我能够编译。

然后我添加我的主机名 setupStream

-(void)setupStream { 
NSLog(@"setupStream"); 
xmppStream = [[[XMPPStream alloc] init]autorelease]; 
xmppStream.hostName=@"talk.google.com"; 
//xmppStream.hostPort=5222; 
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}

但是什么也不会发生..委托(delegate)方法

-(void)xmppStreamDidConnect:(XMPPStream *)sender { 
NSLog(@"didReceiveMessage"); 
isOpen = YES; NSError *error = nil; 
[[self xmppStream] authenticateWithPassword:password error:&error];
}

-(void)xmppStreamDidAuthenticate:(XMPPStream *)sender { 
NSLog(@"didReceiveMessage"); 
[self goOnline];
}

没有被调用。缺少什么。请帮助我..

最佳答案

问题很可能是您的类实例,即您的 XMPPStream 的委托(delegate)在调用委托(delegate)方法之前被释放。通过使此类成为其他类的属性或实例变量或使用 dispatch_once 使其更持久。例如,

改变

YourClass *instance = [[YourClass alloc] init];
instance.xmppStream = .... 

@property(nonatomic, strong) YourClass *instance;
self.instance = [[YourClass alloc] init];
self.instance.xmppStream = .... 

这里 YourClass 包含 XMPPStream 并且是它的委托(delegate)。

我已经写了一篇关于这个问题的大博文。这是很常见的情况。 http://blog.alwawee.com/2013/07/31/on-xmppframework-delegate-method-not-being-called/

关于iphone - 使用 xmpp 框架时未调用委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17044873/

相关文章:

iphone - 更改 IOS 应用程序上 TabBar 应用程序中的当前屏幕

iphone - 新的 YouTube iframe 代码无法在 iPhone 上显示视频

iphone - 如何强制从 iDevice 中删除应用程序

ios - 初始加载 View Controller 不会响应 web View

ios - GMSMapView 跟踪模式标题

ios - 在iOS中使用Touch ID时能否获得每个指纹的唯一值?

ios - 使用 XMPPFramework 上传 vCard 时图像变得难以辨认

iphone - 图像编辑问题

xmpp - 您如何扩展 XMPP 安装?

mysql - ejabberd:从 mysql 数据库中检索聊天记录