• 消息发送,


    第一次见 回调过程发生在 两行代码之间,而不是两个分离的方法,

    //发送信息

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

    }

  • 相关阅读:
    c# 不常用逻辑运算符
    c# 简单日志记录类 log

    最短路径
    A+B
    floyd 算法
    Kruskal 算法
    快排
    顺序表的逆排
    顺序表中多余元素的删除
  • 原文地址:https://www.cnblogs.com/guligei/p/3513954.html
Copyright © 2020-2023  润新知