From dd41973e2e9cd46f97b2b298018c90624d47b763 Mon Sep 17 00:00:00 2001 From: Shaw Date: Sun, 29 Dec 2019 22:41:56 +0800 Subject: [PATCH] bugfix: custom message has no content_type transfer content_type from native to js --- .../java/cn/jiguang/plugins/push/common/JConstants.java | 1 + .../java/cn/jiguang/plugins/push/helper/JPushHelper.java | 1 + index.js | 6 ++++-- ios/RCTJPushModule/RCTJPushModule.m | 6 ++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java b/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java index e1f90bd1..d629fcdc 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java +++ b/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java @@ -25,6 +25,7 @@ public class JConstants { public static final String MESSAGE_ID = "messageID"; public static final String TITLE = "title"; public static final String CONTENT = "content"; + public static final String CONTENT_TYPE = "content_type"; public static final String EXTRAS = "extras"; //消息事件 public static final String NOTIFICATION_ARRIVED = "notificationArrived"; diff --git a/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java b/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java index 86833d69..505c8250 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +++ b/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java @@ -57,6 +57,7 @@ public static WritableMap convertCustomMessage(CustomMessage customMessage) { writableMap.putString(JConstants.MESSAGE_ID, customMessage.messageId); writableMap.putString(JConstants.TITLE, customMessage.title); writableMap.putString(JConstants.CONTENT, customMessage.message); + writableMap.putString(JConstants.CONTENT_TYPE, customMessage.contentType); convertExtras(customMessage.extra, writableMap); return writableMap; } diff --git a/index.js b/index.js index fbafd4c2..304e2d08 100644 --- a/index.js +++ b/index.js @@ -170,7 +170,7 @@ export default class JPush { JPushModule.getAllTags(params) } } - + /* * 设置别名 * 需要理解的是,这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置 @@ -396,12 +396,14 @@ export default class JPush { /* * 自定义消息事件 * - * @param {Fucntion} callback = (result) => {"messageID":String,"content":String,"extras":{String:String}}} + * @param {Fucntion} callback = (result) => {"messageID":String,"content":String, "content_type":String, "extras":{String:String}}} * * messageID:唯一标识自定义消息的 ID * * content:对应 Portal 推送消息界面上的“自定义消息内容”字段 * + * content_type:对应 Portal 推送消息界面上的“自定义消息内容类型”字段 + * * extras:对应 Portal 推送消息界面上的“可选设置”里的附加字段 * * */ diff --git a/ios/RCTJPushModule/RCTJPushModule.m b/ios/RCTJPushModule/RCTJPushModule.m index 4c5e8ba4..063cf3ee 100644 --- a/ios/RCTJPushModule/RCTJPushModule.m +++ b/ios/RCTJPushModule/RCTJPushModule.m @@ -13,6 +13,7 @@ #define MESSAGE_ID @"messageID" #define TITLE @"title" #define CONTENT @"content" +#define CONTENT_TYPE @"content_type" #define EXTRAS @"extras" #define BADGE @"badge" #define RING @"ring" @@ -533,10 +534,11 @@ -(NSDictionary *)convertCustomMessage:(NSNotification *)data NSString *messageID = objectData[@"_j_msgid"]?objectData[@"_j_msgid"]:@""; NSString *title = objectData[@"title"]?objectData[@"title"]:@""; NSString *content = objectData[@"content"]?objectData[@"content"]:@""; + NSString *content_type = objectData[@"content_type"]?objectData[@"content_type"]:@""; if(objectData[@"extras"]){ - responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content,EXTRAS:objectData[@"extras"]}; + responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content,CONTENT_TYPE:content_type,EXTRAS:objectData[@"extras"]}; }else{ - responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content}; + responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content,CONTENT_TYPE:content_type}; } return responseData; }