目录

APNs 内容解析


单聊

不显示详情

{
	"aps":{
		"alert":{
			"body":"您有一条新消息"
		},	 
		"badge":1,				 
		"sound":"default"		 
	},
	"f":"6001",					 
	"t":"6006",					 
	"m":"373360335316321408"			 
}

显示详情

{
	"aps":{
		"alert":{
			"body":"ApnsNickName:xxxx"
		},	 
		"badge":1,				 
		"sound":"default"		 
	},
	"f":"6001",					 
	"t":"6006",					 
	"m":"373360335316321408"			 
}

群聊

不显示详情

{
	"aps":{
		"alert":"您有一条新消息",	 
		"badge":1,				 
		"sound":"default"		 
	},
	"f":"6001",					 
	"t":"6006",	
	"g":"1421300621769",				 
	"m":"373360335316321408"			 
}

显示详情

{
	"aps":{
		"alert":"ApnsName:xxxx",	 
		"badge":1,				 
		"sound":"default"		 
	},
	"f":"6001",					 
	"t":"6006",		
	"g":"1421300621769",
	"m":"373360335316321408"			 
}

向 APNs 中添加扩展字段(em_apns_ext)

APNs扩展:添加后,您收到的 APNs 中将带有您填写的字段,可以帮助您区分 APNs。

解析内容

{
    "apns": {
        "alert": {
            "body": "hello from rest"
        }, 
        "badge": 1, 
        "sound": "default"
    }, 
    "e": "自定义推送扩展", 
    "f": "6001", 
    "t": "6006", 
    "m": "373360335316321408"
}

发送扩展

REST 发送

REST 发消息

{
    "target_type": "users", 
    "target": [
        "6006"
    ], 
    "msg": {
        "type": "txt", 
        "msg": "hello from rest"
    }, 
    "ext": {
        "em_apns_ext": {
            "extern": "自定义推送扩展"
        }
    }, 
    "from": "6001"
}

iOS 发送

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 发送

(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":{
			"body":"自定义推送显示"
		},	 
		"badge":1,				 
		"sound":"default"		 
	},
	"f":"6001",					 
	"t":"6006",					 
	"m":"373360335316321408"			 
}

REST 发送

(REST 发消息)

{
    "target_type": "users", 
    "target": [
        "6006"
    ], 
    "msg": {
        "type": "txt", 
        "msg": "hello from rest"
    }, 
    "from": "6001", 
    "ext": {
        "em_apns_ext": {
            "em_push_content": "自定义推送显示"
        }
    }
}

iOS 发送

(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 发送

(REST 发消息)

{
    "target_type": "users", 
    "target": [
        "6006"
    ], 
    "msg": {
        "type": "txt", 
        "msg": "hello from rest"
    }, 
    "from": "6001", 
    "ext": {
        "em_apns_ext": {
            "em_push_content": "自定义推送显示",
            "extern": "自定义推送扩展"
        }
    }
}

iOS 发送

(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字段

苹果描述

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"
        }
    }
}

上一页:APNs 离线推送

下一页:EaseUI 使用指南