流程,xmpp发送信息,

时间:2022-04-17 14:39:58

1,

-(XMPPMessage *)sendMessage:(NSString *)newMessage andJID:(XMPPJID *)jid

{

    NSXMLElement *body = [NSXMLElementelementWithName:@"body"];

    [body setStringValue:newMessage];

    XMPPMessage *message = [XMPPMessageelementWithName:@"message"];

    [message addAttributeWithName:@"type"stringValue:@"chat"];

    [message addAttributeWithName:@"to"stringValue:@"xiaoqiang@127.0.0.1"];

    [message addAttributeWithName:@"from"stringValue:@"wangyanan@127.0.0.1/openfireiOS"];

    

    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:@"wangyanan1389348892wanghongli"];

    [message addChild:receiptRequest];

    [message addChild:body];

    TTLog(@"xmppmessage :%@",message);

    

    XMPPElementReceipt *receipt = nil;

    [xmppStream sendElement:message andGetReceipt:&receipt];

 

 

2,《

- (XMPPMessage *)xmppStream:(XMPPStream *)sender willSendMessage:(XMPPMessage *)message

{

    TTLog(@"%@",message);

    return message;

}

3,《

- (void)xmppStream:(XMPPStream *)sender didSendMessage:(XMPPMessage *)message

{

    TTLog(@"%@",message);

 

}

4,

    if ([receipt wait:-1])

    {

        TTLog(@"was sent");

    }

    else{

        TTLog(@"sent faild");

    }

    return message;

}