【问题标题】:XMPPFramework send element method is not called未调用 XMPPFramework 发送元素方法
【发布时间】:2015-12-14 00:14:51
【问题描述】:

您好,我正在使用 XMPPFramework 制作聊天应用。

我通过引用此链接在我的项目中设置了 XMPPFramework:- http://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-xmpp-setup--mobile-7190

发送消息的代码:-

    NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
    [body setStringValue:messageStr];

    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:fnjid];
    [message addChild:body];
    [self.xmppStream sendElement:message];

这段代码运行良好,但现在不起作用...方法“send Element”没有调用...它在 xmppstream 类中。

- (void)sendElement:(NSXMLElement *)element

此方法在连接到服务器时调用,但仅在发送消息时不工作

【问题讨论】:

  • sendElement: 未被调用时,self.xmppStream 是否为零?

标签: ios objective-c xmppframework


【解决方案1】:

可能,你的化合物和授权有问题?

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    isXmppConnected = YES;
    NSError *error = nil;
    if (![[self xmppStream] authenticateWithPassword:password error:&error])
    {

    }
}

And

- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
    XMPPPresence *presence = [XMPPPresence presenceWithType:@"available"];
    [[self xmppStream] sendElement:presence];
}


In this case, the method does not work correctly , because state != STATE_XMPP_CONNECTED

- (void)sendElement:(NSXMLElement *)element
{
 if (element == nil) return;

 dispatch_block_t block = ^{ @autoreleasepool {

  if (state == STATE_XMPP_CONNECTED)
  {
   [self sendElement:element withTag:TAG_XMPP_WRITE_STREAM];
  }
  else
  {
   [self failToSendElement:element];
  }
 }};

 if (dispatch_get_specific(xmppQueueTag))
  block();
 else
  dispatch_async(xmppQueue, block);
}

【讨论】:

    猜你喜欢
    • 2012-06-21
    • 1970-01-01
    • 2014-09-23
    • 2012-06-15
    • 2013-01-15
    • 2023-01-09
    • 2012-10-26
    • 1970-01-01
    相关资源
    最近更新 更多