====== APNs 内容解析 ====== ---- ===== 单聊 ===== ==== 不显示详情 ==== { "aps":{ "alert":{ "body":"您有一条新消息" }, "badge":1, "sound":"default" }, "f":"6001", "t":"6006", "m":"373360335316321408" } * alert: 显示信息 * badge: 角标,表示离线消息数 * sound: 收到 APNs 时的提示音 * f: 消息发送方的环信 ID * t: 消息接收方的环信 ID * m: 消息 ID ==== 显示详情 ==== { "aps":{ "alert":{ "body":"ApnsNickName:xxxx" }, "badge":1, "sound":"default" }, "f":"6001", "t":"6006", "m":"373360335316321408" } * alert: 显示信息 * ApnsName: 发送方设置的用户名(即环信管理后台中看到的用户昵称) * xxxx: 消息内容(发送方发的什么,就显示什么) * badge: 角标,表示离线消息数 * sound: 收到 APNs 时的提示音 * f: 消息发送方的环信 ID * t: 消息接收方的环信 ID * m: 消息 ID ===== 群聊 ===== ==== 不显示详情 ==== { "aps":{ "alert":"您有一条新消息", "badge":1, "sound":"default" }, "f":"6001", "t":"6006", "g":"1421300621769", "m":"373360335316321408" } * alert: 显示信息 * badge: 角标,表示离线消息数 * sound: 收到 APNs 时的提示音 * f: 消息发送方的环信 ID * t: 消息接收方的环信 ID * g: 群组 ID * m: 消息 ID ==== 显示详情 ==== { "aps":{ "alert":"ApnsName:xxxx", "badge":1, "sound":"default" }, "f":"6001", "t":"6006", "g":"1421300621769", "m":"373360335316321408" } * alert: 显示信息 * ApnsName: 发送方设置的用户名(即环信管理后台中看到的用户昵称) * xxxx: 消息内容(发送方发的什么,就显示什么) * badge: 角标,表示离线消息数 * sound: 收到 APNs 时的提示音 * f: 消息发送方的环信 ID * t: 消息接收方的环信 ID * g: 群组 ID * m: 消息 ID ===== 向 APNs 中添加扩展字段(em_apns_ext) ===== APNs扩展:添加后,您收到的 APNs 中将带有您填写的字段,可以帮助您区分 APNs。 ==== 解析内容 ==== { "apns": { "alert": { "body": "hello from rest" }, "badge": 1, "sound": "default" }, "e": "自定义推送扩展", "f": "6001", "t": "6006", "m": "373360335316321408" } * e: 您发送的自定义推送扩展 ==== 发送扩展 ==== === REST 发送 === ([[im:100serverintegration:50messages#发送文本消息|REST 发消息]]) { "target_type": "users", "target": [ "6006" ], "msg": { "type": "txt", "msg": "hello from rest" }, "ext": { "em_apns_ext": { "extern": "自定义推送扩展" } }, "from": "6001" } === iOS 发送 === ([[im:300iosclientintegration:40emmsg#构造消息|iOS 发消息]]) EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:@"test"]; EMMessage *message = [[EMMessage alloc] initWithConversationID:@"6006" from:@"6001" to:@"6006" body:body ext:nil]; message.ext = @{@"em_apns_ext":@{@"extern":@"自定义推送扩展"}}; // 此处的ext和message初始化时传递的ext效果是一样的,此处单独抽出来的目的是表示的更清晰。 message.chatType = EMChatTypeChat; // 设置消息类型 [EMClient.sharedClient.chatManager sendMessage:message progress:nil completion:nil]; ===== 发送静默消息(不发APNs,em_ignore_notification) ===== 发送时添加后,该消息将不会有 APNs 推送。 ==== REST 发送 ==== ([[im:100serverintegration:50messages#发送文本消息|REST 发消息]]) { "target_type":"users", "target":[ "6006" ], "msg":{ "type":"txt", "msg":"hello from rest" }, "from":"6001", "ext":{ "em_ignore_notification":true } } ==== iOS 发送 ==== ([[im:300iosclientintegration:40emmsg#构造消息|iOS 发消息]]) EMChatText *txt = [[EMChatText alloc] initWithText:@"test"]; EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithChatObject:txt]; EMMessage *msg = [[EMMessage alloc] initWithReceiver:@"6001" bodies:@[body]]; // 设置自定义扩展字段 msg.ext = @{@"em_ignore_notification":@YES}; // 发送消息 [[EaseMob sharedInstance].chatManager asyncSendMessage:msg progress:nil]; ===== 设置强制推送型 APNs(em_force_notification) ===== 设置后,将强制推送消息,即使客户端设置了免打扰时间,也会得到推送。优先级比 em_ignore_notification 低,即同时设置 em_ignore_notification 后,该属性将失效。 ==== REST 发送 ==== ([[im:100serverintegration:50messages#发送文本消息|REST 发消息]]) { "target_type":"users", "target":[ "6006" ], "msg":{ "type":"txt", "msg":"hello from rest" }, "from":"6001", "ext":{ "em_force_notification":true } } ==== iOS 发送 ==== ([[im:300iosclientintegration:40emmsg#构造消息|iOS 发消息]]) EMChatText *txt = [[EMChatText alloc] initWithText:@"test"]; EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithChatObject:txt]; EMMessage *msg = [[EMMessage alloc] initWithReceiver:@"6001" bodies:@[body]]; // 设置自定义扩展字段 msg.ext = @{@"em_force_notification":@YES}; // 发送消息 [[EaseMob sharedInstance].chatManager asyncSendMessage:msg progress:nil]; ===== 自定义显示 ===== 设置后,您收到的 APNs 的 alert 信息将是您设置的信息。 ==== 解析 ==== { "aps":{ "alert":{ "body":"自定义推送显示" }, "badge":1, "sound":"default" }, "f":"6001", "t":"6006", "m":"373360335316321408" } ==== REST 发送 ==== ([[im:100serverintegration:50messages#发送文本消息|REST 发消息]]) { "target_type": "users", "target": [ "6006" ], "msg": { "type": "txt", "msg": "hello from rest" }, "from": "6001", "ext": { "em_apns_ext": { "em_push_content": "自定义推送显示" } } } ==== iOS 发送 ==== ([[im:300iosclientintegration:40emmsg#构造消息|iOS 发消息]]) EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:@"test"]; EMMessage *message = [[EMMessage alloc] initWithConversationID:@"6006" from:@"6001" to:@"6006" body:body ext:nil]; message.ext = @{@"em_apns_ext":@{@"em_push_content":@"自定义推送显示"}}; // 此处的ext和message初始化时传递的ext效果是一样的,此处单独抽出来的目的是表示的更清晰。 message.chatType = EMChatTypeChat; // 设置消息类型 [EMClient.sharedClient.chatManager sendMessage:message progress:nil completion:nil]; ===== 自定义显示与自定义扩展同时发给对方 ===== ==== 解析 ==== { "aps":{ "alert":{ "body":"自定义推送显示" }, "badge":1, "sound":"default" }, "f":"6001", "t":"6006", "m":"373360335316321408", "e": "自定义推送扩展", } ==== REST 发送 ==== ([[im:100serverintegration:50messages#发送文本消息|REST 发消息]]) { "target_type": "users", "target": [ "6006" ], "msg": { "type": "txt", "msg": "hello from rest" }, "from": "6001", "ext": { "em_apns_ext": { "em_push_content": "自定义推送显示", "extern": "自定义推送扩展" } } } ==== iOS 发送 ==== ([[im:300iosclientintegration:40emmsg#构造消息|iOS 发消息]]) NSString *willSendText = [EaseConvertToCommonEmoticonsHelper convertToCommonEmoticons:text]; EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:@"test"]; EMMessage *message = [[EMMessage alloc] initWithConversationID:@"6006" from:@"6001" to:@"6006" body:body ext:nil]; message.ext = @{@"em_apns_ext":@{@"extern":@"自定义推送扩展",@"em_push_content":@"自定义推送显示"}}; // 此处的ext和message初始化时传递的ext效果是一样的,此处单独抽出来的目的是表示的更清晰。 message.chatType = EMChatTypeChat; // 设置消息类型 [EMClient.sharedClient.chatManager sendMessage:message progress:nil completion:nil]; ===== 向APNs Payload中添加category字段 ===== [[https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1|苹果描述]] ==== REST 发送 ==== { "target_type": "users", "target": [ "6006" ], "msg": { "type": "txt", "msg": "hello from rest" }, "from": "6001", "ext": { "em_apns_ext": { "em_push_category" : "NEW_MESSAGE_CATEGORY" } } } ---- 上一页:[[im:300iosclientintegration:75apns|APNs 离线推送]] 下一页:[[im:300iosclientintegration:85easeuiguide|EaseUI 使用指南]]