第一次见 回调过程发生在 两行代码之间,而不是两个分离的方法,
//发送信息
-(XMPPMessage *)sendMessage:(NSString *)mess andJID:(XMPPJID *)jid
{
NSXMLElement *body = [NSXMLElementelementWithName:@"body"];
[body setStringValue:mess];
XMPPMessage *message = [XMPPMessageelementWithName:@"message"];
[message addAttributeWithName:@"type"stringValue:@"chat"];
[message addAttributeWithName:@"to"stringValue:[jid full]];
[message addAttributeWithName:@"from"stringValue:@"wangyanan@127.0.0.1"];
NSXMLElement * receiptRequest = [NSXMLElement elementWithName:@"request"];
[receiptRequest addAttributeWithName:@"xmlns"stringValue:@"urn:xmpp:receipts"];
int timeStamp = (int)[[NSDate date] timeIntervalSince1970];
NSString * messageID = [NSString stringWithFormat:@"%@%d%@",[[message attributeForName:@"from"]stringValue],timeStamp,[[message attributeForName:@"to"]stringValue]];
[message addAttributeWithName:@"id"stringValue:messageID];
[message addChild:receiptRequest];
[message addChild:body];
TTLog(@"xmppmessage :%@",message);
XMPPElementReceipt *receipt = [XMPPElementReceiptnew];
[mStream sendElement:message andGetReceipt:&receipt];
BOOL messageState =[receipt wait:-1];
if (messageState)
{
TTLog(@"was sent");
}
else{
TTLog(@"sent faild");
}
return message;
}