极光JMessage


1.集成:

  1. 把 JMessage.framework 文件加入到项目里。
  2. 把 JMessafe.framework 目录下的 jcore-ios-x.x.x.a(x.x.x 为jcore 版本号) link 到工程中。(注意:link到JMessafe.framework下的core-ios-x.x.x.a添加);
2.:消息返回方法调用

实现<JMessageDelegate,JMSGMessageDelegate>   

[JMessage addDelegate:self withConversation:nil];


- (void)onReceiveMessage:(JMSGMessage *)message

                   error:(NSError *)error

{

/*************----下面是收到消息设置免打扰---*************************/

      //设置免打扰(消息是可以收到的,只是 不会收到通知提醒而已。进入app后依旧可以收到消息的

     JMSGUser *sure=message.fromUser;

      BOOL isAlreadSet = sure.isNoDisturb;

    

    if (!isAlreadSet) {

        [sure setIsNoDisturb:YES handler:^(id resultObject, NSError *error) {

            if (!error) {

                NSLog(@"\n消息免打扰设置成功:\n%@\n",resultObject);

            }

            

        }];


        

    }


/*************----下面是收到消息的处理---*************************/


     // 1.分装好的类               JMSGTextContent, JMSGImageContent, JMSGVoiceContent,                                  JMSGCustomContent


   //  2. message.contentType


 /// 不知道类型的消息

//    kJMSGContentTypeUnknown = 0,

//    /// 文本消息

//    kJMSGContentTypeText = 1,

//    /// 图片消息

//    kJMSGContentTypeImage = 2,

//    /// 语音消息

//    kJMSGContentTypeVoice = 3,

//    /// 自定义消息

//    kJMSGContentTypeCustom = 4,

//    /// 事件通知消息。服务器端下发的事件通知,本地展示为这个类型的消息展示出来

//    kJMSGContentTypeEventNotification = 5,

//    /// 文件消息

//    kJMSGContentTypeFile = 6,

//    /// 地理位置消息

//    kJMSGContentTypeLocation = 7,


      //例子: 文本

        if (message.contentType == kJMSGContentTypeText) {

                JMSGTextContent *textContent = (JMSGTextContent *)message.content;

            

           NSLog(@"--------文本--------%@",textContent.text);

            NSLog(@"---------文本附加消息---------%@", textContent.extras);

        }


}

 3.消息发送

(1)用分装好的类发送

列如:

 [JMSGMessage sendSingleTextMessage:@"nihao" toUser:@"dama"];


(2)创建私聊再发送


(3)自定义发送(可以自己添加一些定义的值)

    (1)。addStringExtra

       

  NSString *path= [[NSBundle mainBundle]pathForResource:@"Glass.WAV" ofType:nil];

     NSData *voiceData=[NSData dataWithContentsOfFile:path];

    JMSGVoiceContent * content=[[JMSGVoiceContent alloc]initWithVoiceData:voiceData voiceDuration:[NSNumber numberWithInt:1]];

    [content addStringExtra:@"XiaoGou" forKey:@"Name"];

    JMSGMessage *GG=[JMSGMessage createSingleMessageWithContent:content username:@"tianqi"];

    [JMSGMessage sendMessage:GG];


    (2)JMSGCustomContent

      

 JMSGConversation     *sation= [JMSGConversation singleConversationWithUsername:@"dama" appKey:@"c85d8c0baecc0683d7cbafe4"];

  JMSGCustomContent *custom=[[JMSGCustomContent alloc]initWithCustomDictionary:@{@"Wifi":@"sdw",@"Password":@"1235677"}];

    JMSGMessage *mj= [sation createMessageWithContent:custom];

        [sation sendMessage:mj];



    // value . 必须满足 JSON Value 的要求, 基本规则是: NSNumber, NSString, NSArray, NSDictionary


    JMSGCustomContent *custom=[[JMSGCustomContent alloc]initWithCustomDictionary:@{@"name":@"sdw",@"Age":@(12),}];

    

    JMSGMessage *ff=[JMSGMessage createSingleMessageWithContent:custom username:@"dama"];

    [JMSGMessage sendMessage:ff];





 (4)跨应用发送

[JMSGMessage sendSingleTextMessage:@"老驴" toUser:@"zhangsan" appKey:@"2f0e7f4b02ad46860cbc61ba"];







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值