版本記錄
版本號 | 時間 |
---|---|
V1.0 | 2017.06.10 |
前言
很多app種都集成環信做第三方信息通訊工具,這里我們就看一下環信的主要功能和集成方法。先給出環信3.0的地址。
感興趣的可以參考:
1. 環信ios客戶端的集成(一)
2. 環信ios客戶端的集成(二)
3. 環信ios客戶端的集成(三)
4. 環信ios客戶端的集成(四)
5. 環信ios客戶端的集成(五)
6. 環信ios客戶端的集成(六)
7. 環信ios客戶端的集成(七)
8. 環信ios客戶端的集成(八)
9. 環信ios客戶端的集成(九)
10. 環信ios客戶端的集成(十)
11. 環信ios客戶端的集成(十一)
這一篇主要說一下環信的 APNS 內容解析
一、單聊
1.不顯示詳情
{
"aps":{
"alert":"您有一條新消息",
"badge":1,
"sound":"default"
},
"f":"6001",
"t":"6006",
"m":"14aec1e00ef"
}
- alert: 顯示信息
- badge: 角標,表示離線消息數
- sound: 收到 APNS 時的提示音
- f: 消息發送方的環信 ID
- t: 消息接收方的環信 ID
- m: 消息 ID
2.顯示詳情
{
"aps":{
"alert":"ApnsName:xxxx",
"badge":1,
"sound":"default"
},
"f":"6001",
"t":"6006",
"m":"14aec1e00ef"
}
- alert: 顯示信息
- ApnsName: 發送方設置的用戶名(即環信管理后臺中看到的用戶昵稱)
- xxxx: 消息內容(發送方發的什么,就顯示什么)
- badge: 角標,表示離線消息數
- sound: 收到 APNS 時的提示音
- f: 消息發送方的環信 ID
- t: 消息接收方的環信 ID
- m: 消息 ID
二、群聊
1.不顯示詳情
{
"aps":{
"alert":"您有一條新消息",
"badge":1,
"sound":"default"
},
"f":"6001",
"t":"6006",
"g":"1421300621769",
"m":"14aec1e00ef"
}
- alert: 顯示信息
- badge: 角標,表示離線消息數
- sound: 收到 APNS 時的提示音
- f: 消息發送方的環信 ID
- t: 消息接收方的環信 ID
- g: 群組 ID
- m: 消息 ID
2.顯示詳情
{
"aps":{
"alert":"ApnsName:xxxx",
"badge":1,
"sound":"default"
},
"f":"6001",
"t":"6006",
"g":"1421300621769",
"m":"14aec1e00ef"
}
- alert: 顯示信息
- ApnsName: 發送方設置的用戶名(即環信管理后臺中看到的用戶昵稱)
- xxxx: 消息內容(發送方發的什么,就顯示什么)
- badge: 角標,表示離線消息數
- sound: 收到 APNS 時的提示音
- f: 消息發送方的環信 ID
- t: 消息接收方的環信 ID
- g: 群組 ID
- m: 消息 ID
三、向 APNS 中添加擴展字段(em_apns_ext)
APNS擴展:添加后,您收到的 APNS 中將帶有您填寫的字段,可以幫助您區分 APNS。
1.解析內容
{
"aps":{
"alert":"您有一條新消息",
"badge":1,
"sound":"default"
},
"f":"6001",
"t":"6006",
"e":"擴展內容",
"m":"14aec1e00ef"
}
- e: 您發送的自定義內容
2.發送擴展
REST 發送
(REST 發消息)
{
"target_type":"users",
"target":[
"6006"
],
"msg":{
"type":"txt",
"msg":"hello from rest"
},
"from":"6001",
"ext":{
"em_apns_ext":"擴展內容"
}
}
iOS 發送
(iOS 發消息)
EMChatText *txt = [[EMChatText alloc] initWithText:@"test"];
EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithChatObject:txt];
EMMessage *msg = [[EMMessage alloc] initWithReceiver:@"6001" bodies:@[body]];
// 設置自定義擴展字段
msg.ext = @{@"em_apns_ext":@"擴展內容"};
// 發送消息
[[EaseMob sharedInstance].chatManager asyncSendMessage:msg progress:nil];
四、 發送靜默消息(不發APNS,em_ignore_notification)
發送時添加后,該消息將不會有 APNS 推送。
REST 發送
(REST 發消息)
{
"target_type":"users",
"target":[
"6006"
],
"msg":{
"type":"txt",
"msg":"hello from rest"
},
"from":"6001",
"ext":{
"em_ignore_notification":true
}
}
iOS 發送
(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 發送
(REST 發消息)
{
"target_type":"users",
"target":[
"6006"
],
"msg":{
"type":"txt",
"msg":"hello from rest"
},
"from":"6001",
"ext":{
"em_force_notification":true
}
}
iOS 發送
(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":"自定義信息",
"badge":1,
"sound":"default"
},
"f":"6001",
"t":"6006",
"m":"14aec1e00ef"
}
REST 發送
(REST 發消息)
{
"target_type":"users",
"target":[
"6006"
],
"msg":{
"type":"txt",
"msg":"hello from rest"
},
"from":"6001",
"ext":{
"em_apns_ext":{
"em_push_title":"自定義信息"
}
}
}
iOS 發送
(iOS 發消息)
EMChatText *txt = [[EMChatText alloc] initWithText:@"test"];
EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithChatObject:txt];
EMMessage *msg = [[EMMessage alloc] initWithReceiver:@"6001" bodies:@[body]];
// 設置自定義擴展字段
msg.ext = @{@"em_apns_ext":@{@"em_push_title":@"自定義信息"}};
// 發送消息
[[EaseMob sharedInstance].chatManager asyncSendMessage:msg progress:nil];
七、自定義顯示與自定義擴展同時發給對方
解析
{
"aps":{
"alert":"自定義信息",
"badge":1,
"sound":"default"
},
"f":"6001",
"t":"6006",
"m":"14aec1e00ef",
"e":"擴展內容"
}
REST 發送
(REST 發消息)
{
"target_type":"users",
"target":[
"6006"
],
"msg":{
"type":"txt",
"msg":"hello from rest"
},
"from":"6001",
"ext":{
"em_apns_ext":{
"em_push_title":"自定義信息",
"extern": "擴展內容"
}
}
}
iOS 發送
(iOS 發消息)
EMChatText *txt = [[EMChatText alloc] initWithText:@"test"];
EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithChatObject:txt];
EMMessage *msg = [[EMMessage alloc] initWithReceiver:@"6001" bodies:@[body]];
// 設置自定義擴展字段
msg.ext = @{@"em_apns_ext":@{@"em_push_title":@"自定義信息",@"extern":@"擴展內容"}};
// 發送消息
[[EaseMob sharedInstance].chatManager asyncSendMessage:msg progress:nil];
后記
未完,待續~~~
美得不像話