zoukankan      html  css  js  c++  java
  • 消息发送,

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

    //发送信息

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

    }

  • 相关阅读:
    [LeetCode] Next Greater Element I
    [LeetCode] Fizz Buzz
    [LeetCode] Reverse String
    [LeetCode] Average of Levels in Binary Tree
    [LeetCode] Encode and Decode TinyURL
    推荐一个计算机视觉图书:python计算机视觉编程
    leetcode 9 Palindrome Number 回文数
    ios swift模仿qq登陆界面,xml布局
    leetcode 26 Remove Duplicates from Sorted Array
    leetcode 88 Merge Sorted Array
  • 原文地址:https://www.cnblogs.com/guligei/p/3513954.html
Copyright © 2011-2022 走看看