【问题标题】:Delegate method not being called when using xmpp framework使用 xmpp 框架时未调用委托方法
【发布时间】:2013-06-11 13:06:20
【问题描述】:

我正在使用 xcode 4.5 从此链接下载示例项目。 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()];
}

但是什么都不会发生..委托方法

-(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];
}

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

【问题讨论】:

    标签: iphone ios xmppframework


    【解决方案1】:

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

    改变

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

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

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

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

    【讨论】:

    【解决方案2】:

    Connecting

    准备就绪后,就可以开始连接过程了:

    NSError *error = nil;
    if (![xmppStream connect:&error])
    {
        NSLog(@"Oops, I probably forgot something: %@", error);
    }
    

    由于您没有做任何事情,因此不会调用委托方法。根据XMPPStream 的实现,您很可能会遇到大量内存问题,请在某处添加对已分配对象的保留引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      相关资源
      最近更新 更多