1.集成:
- 把 JMessage.framework 文件加入到项目里。
- 把 JMessafe.framework 目录下的 jcore-ios-x.x.x.a(x.x.x 为jcore 版本号) link 到工程中。(注意:link到JMessafe.framework下的core-ios-x.x.x.a添加);
实现<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"];
(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"];