gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:18:04 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com