你好,我正在制作一个使用XMPPFramework的聊天应用程序。
我已经在我的项目中设置了XMPPFramework参考这个链接:-http://code.tutsplus.com/tutorials/building - - jabber客户机- ios xmpp -设置-手机- 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];
这段代码工作得很好,但现在这是不工作…方法"发送元素"没有调用,它在xmppstream类中。
- (void)sendElement:(NSXMLElement *)element
此方法在连接到服务器时调用,但仅在发送消息时不起作用
可能您的复方和授权有问题?
- (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);
}