Skip to content

Commit 1b5d7fd

Browse files
author
wicked-tc130
authored
Merge pull request #679 from jpush/dev
升级到2.5.9.5
2 parents 2129a4e + 4f701dc commit 1b5d7fd

File tree

8 files changed

+132
-131
lines changed

8 files changed

+132
-131
lines changed

android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public static WritableMap convertNotificationBundleToMap(String eventType, Bundl
5252
return writableMap;
5353
}
5454

55-
5655
public static WritableMap convertCustomMessage(CustomMessage customMessage) {
5756
WritableMap writableMap = Arguments.createMap();
5857
writableMap.putString(JPushConstans.MESSAGE_ID, customMessage.messageId);
58+
writableMap.putString(JPushConstans.TITLE, customMessage.title);
5959
writableMap.putString(JPushConstans.CONTENT, customMessage.message);
6060
convertExtras(customMessage.extra, writableMap);
6161
return writableMap;

example/ios/example/AppDelegate.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2323
// JPush初始化配置
2424
[JPUSHService setupWithOption:launchOptions appKey:@"129c21dc4cb5e6f6de194003"
2525
channel:@"dev" apsForProduction:YES];
26-
// Apns
26+
// APNS
2727
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
2828
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
2929
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
@@ -51,15 +51,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5151

5252
//************************************************JPush start************************************************
5353

54-
//注册 APNs 成功并上报 DeviceToken
54+
//注册 APNS 成功并上报 DeviceToken
5555
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
5656
[JPUSHService registerDeviceToken:deviceToken];
5757
}
5858

59-
//iOS 7 Apns
59+
//iOS 7 APNS
6060
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
6161
// iOS 10 以下 Required
62-
NSLog(@"iOS 7 Apns");
62+
NSLog(@"iOS 7 APNS");
6363
[JPUSHService handleRemoteNotification:userInfo];
6464
[[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_ARRIVED_EVENT object:userInfo];
6565
completionHandler(UIBackgroundFetchResultNewData);
@@ -77,7 +77,7 @@ - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentN
7777
NSDictionary * userInfo = notification.request.content.userInfo;
7878
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
7979
// Apns
80-
NSLog(@"iOS 10 Apns 前台收到消息");
80+
NSLog(@"iOS 10 APNS 前台收到消息");
8181
[JPUSHService handleRemoteNotification:userInfo];
8282
[[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_ARRIVED_EVENT object:userInfo];
8383
}
@@ -93,17 +93,20 @@ - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentN
9393
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler: (void (^)())completionHandler {
9494
NSDictionary * userInfo = response.notification.request.content.userInfo;
9595
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
96-
NSLog(@"iOS 10 Apns 消息事件回调");
96+
NSLog(@"iOS 10 APNS 消息事件回调");
9797
// Apns
9898
[JPUSHService handleRemoteNotification:userInfo];
99+
// 保障应用被杀死状态下,用户点击推送消息,打开app后可以收到点击通知事件
100+
[[RCTJPushEventQueue sharedInstance]._notificationQueue insertObject:userInfo atIndex:0];
99101
[[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_OPENED_EVENT object:userInfo];
100102
}
101103
else {
102104
// 本地通知 todo
103105
NSLog(@"iOS 10 本地通知 消息事件回调");
104106
[[NSNotificationCenter defaultCenter] postNotificationName:J_LOCAL_NOTIFICATION_EVENT object:userInfo];
105107
}
106-
completionHandler(); // 系统要求执行这个方法
108+
// 系统要求执行这个方法
109+
completionHandler();
107110
}
108111

109112
//自定义消息

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export default class JPush {
3434
static init() {
3535
if (Platform.OS == "android") {
3636
JPushModule.init()
37+
}else{
38+
JPushModule.loadJS()
3739
}
3840
}
3941

@@ -324,7 +326,7 @@ export default class JPush {
324326
/*
325327
* 通知事件
326328
*
327-
* @param {Fucntion} callback = (result) => {"messageID":int,"title":int,"content":StringArray,"extras":{String:String}},"notificationType":String}
329+
* @param {Fucntion} callback = (result) => {"messageID":String,"title":String,"content":String,"extras":{String:String},"notificationEventType":String}
328330
*
329331
* messageID:唯一标识通知消息的 ID
330332
*
@@ -334,11 +336,9 @@ export default class JPush {
334336
*
335337
* extras:对应 Portal 推送消息界面上的“可选设置”里的附加字段
336338
*
337-
* notificationType:分为notificationArrived和notificationOpened两种
339+
* notificationEventType:分为notificationArrived和notificationOpened两种
338340
*
339-
* 注意:1.应用在存活状态下点击通知不会有跳转行为,应用在被杀死状态下点击通知会启动应用
340-
* 2.请在JS的componentDidMount()中调用JPush.init()保证消息点击事件到达率
341-
* 3.请在Android的Application onCreate()中调用JPushModule.registerActivityLifecycle(this)保证应用后台点击通知能切到前台
341+
* 注意:应用在存活状态下点击通知不会有跳转行为,应用在被杀死状态下点击通知会启动应用
342342
*
343343
* */
344344
static addNotificationListener(callback) {
@@ -351,7 +351,7 @@ export default class JPush {
351351
/*
352352
* 自定义消息事件
353353
*
354-
* @param {Fucntion} callback = (result) => {"messageID":int,"content":StringArray,"extras":{String:String}}}
354+
* @param {Fucntion} callback = (result) => {"messageID":String,"content":String,"extras":{String:String}}}
355355
*
356356
* messageID:唯一标识自定义消息的 ID
357357
*
@@ -378,7 +378,7 @@ export default class JPush {
378378
/*
379379
* tag alias事件
380380
*
381-
* @param {Fucntion} callback = (result) => {"code":int,"sequence":int,"tags":StringArray,"tag":String,"tagEnable":boolean,"alias":String}
381+
* @param {Fucntion} callback = (result) => {"code":int,"sequence":int,"tags":String,"tag":String,"tagEnable":boolean,"alias":String}
382382
*
383383
* code:结果,0为操作成功
384384
*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// RCTJPushEventQueue.h
3+
// DoubleConversion
4+
//
5+
// Created by wicked on 2019/9/26.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
11+
@interface RCTJPushEventQueue : NSObject
12+
13+
+ (nonnull instancetype) sharedInstance;
14+
15+
@property NSMutableArray<NSDictionary *> *_notificationQueue;;
16+
17+
@end
18+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// RCTJPushEventQueue.m
3+
// DoubleConversion
4+
//
5+
// Created by wicked on 2019/9/26.
6+
//
7+
8+
#import "RCTJPushEventQueue.h"
9+
10+
@implementation RCTJPushEventQueue
11+
12+
+ (instancetype)sharedInstance {
13+
static RCTJPushEventQueue *instance = nil;
14+
static dispatch_once_t onceToken;
15+
dispatch_once(&onceToken, ^{
16+
instance = [[self alloc] init];
17+
});
18+
return instance;
19+
}
20+
21+
- (instancetype)init
22+
{
23+
self = [super init];
24+
if (self) {
25+
self._notificationQueue = [NSMutableArray new];
26+
}
27+
return self;
28+
}
29+
30+
31+
@end

ios/RCTJPushModule/RCTJPushModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#endif
1212

1313
#import "JPUSHService.h"
14+
#import "RCTJPushEventQueue.h"
1415

1516
#define J_APNS_NOTIFICATION_ARRIVED_EVENT @"J_APNS_NOTIFICATION_ARRIVED_EVENT"
1617
#define J_APNS_NOTIFICATION_OPENED_EVENT @"J_APNS_NOTIFICATION_OPENED_EVENT"

ios/RCTJPushModule/RCTJPushModule.m

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
//通知事件类型
2929
#define NOTIFICATION_TYPE @"notificationType"
30+
#define NOTIFICATION_EVENT_TYPE @"notificationEventType"
3031
#define NOTIFICATION_ARRIVED @"notificationArrived"
3132
#define NOTIFICATION_OPENED @"notificationOpened"
3233
#define NOTIFICATION_DISMISSED @"notificationDismissed"
@@ -51,7 +52,8 @@ @implementation RCTJPushModule
5152

5253
RCT_EXPORT_MODULE(JPushModule);
5354

54-
- (id)init {
55+
- (id)init
56+
{
5557
self = [super init];
5658
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
5759

@@ -95,7 +97,6 @@ - (id)init {
9597
return self;
9698
}
9799

98-
99100
RCT_EXPORT_METHOD(setDebugMode: (NSDictionary *)options)
100101
{
101102
BOOL isDebug = false;
@@ -107,6 +108,14 @@ - (id)init {
107108
}
108109
}
109110

111+
RCT_EXPORT_METHOD(loadJS)
112+
{
113+
NSMutableArray *list = [RCTJPushEventQueue sharedInstance]._notificationQueue;
114+
if(list.count) {
115+
[self sendApnsNotificationEventByDictionary:list[0]];
116+
}
117+
}
118+
110119
RCT_EXPORT_METHOD(getRegisterId:(RCTResponseSenderBlock) callback)
111120
{
112121
[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
@@ -116,7 +125,6 @@ - (id)init {
116125
}];
117126
}
118127

119-
120128
//tag
121129
RCT_EXPORT_METHOD(addTags:(NSDictionary *)params)
122130
{
@@ -298,13 +306,29 @@ - (void)sendConnectEvent:(NSNotification *)data {
298306
completion:NULL];
299307
}
300308

309+
//APNS通知消息
301310
- (void)sendApnsNotificationEvent:(NSNotification *)data
302311
{
303312
NSDictionary *responseData = [self convertApnsMessage:data];
304313
[self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
305314
method:@"emit"
306315
args:@[NOTIFICATION_EVENT, responseData]
307316
completion:NULL];
317+
if([RCTJPushEventQueue sharedInstance]._notificationQueue.count){
318+
[[RCTJPushEventQueue sharedInstance]._notificationQueue removeAllObjects];
319+
}
320+
}
321+
322+
- (void)sendApnsNotificationEventByDictionary:(NSDictionary *)data
323+
{
324+
NSDictionary *responseData = [self convertApnsMessage:data];
325+
[self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
326+
method:@"emit"
327+
args:@[NOTIFICATION_EVENT, responseData]
328+
completion:NULL];
329+
if([RCTJPushEventQueue sharedInstance]._notificationQueue.count){
330+
[[RCTJPushEventQueue sharedInstance]._notificationQueue removeAllObjects];
331+
}
308332
}
309333

310334
//自定义消息
@@ -356,10 +380,18 @@ -(NSDictionary *)convertConnect:(NSNotification *)data {
356380
return responseData;
357381
}
358382

359-
-(NSDictionary *)convertApnsMessage:(NSNotification *)data{
360-
NSNotificationName notificationName = data.name;
361-
NSDictionary *objectData = data.object;
362-
NSString *notificationType = ([notificationName isEqualToString:J_APNS_NOTIFICATION_OPENED_EVENT])?NOTIFICATION_OPENED:NOTIFICATION_ARRIVED;
383+
-(NSDictionary *)convertApnsMessage:(id)data
384+
{
385+
NSNotificationName notificationName;
386+
NSDictionary *objectData;
387+
if([data isKindOfClass:[NSNotification class]]){
388+
notificationName = [(NSNotification *)data name];
389+
objectData = [(NSNotification *)data object];
390+
}else if([data isKindOfClass:[NSDictionary class]]){
391+
notificationName = J_APNS_NOTIFICATION_OPENED_EVENT;
392+
objectData = data;
393+
}
394+
NSString *notificationEventType = ([notificationName isEqualToString:J_APNS_NOTIFICATION_OPENED_EVENT])?NOTIFICATION_OPENED:NOTIFICATION_ARRIVED;
363395
id alertData = objectData[@"aps"][@"alert"];
364396
NSString *title = @"";
365397
NSString *content = @"";
@@ -370,7 +402,6 @@ -(NSDictionary *)convertApnsMessage:(NSNotification *)data{
370402
title = alertData[@"title"]?alertData[@"title"]:@"";
371403
content = alertData[@"body"]?alertData[@"body"]:@"";
372404
}
373-
374405
NSDictionary *responseData;
375406
NSMutableDictionary * copyData = [[NSMutableDictionary alloc] initWithDictionary:objectData];
376407
if (copyData[@"_j_business"]) {
@@ -392,28 +423,33 @@ -(NSDictionary *)convertApnsMessage:(NSNotification *)data{
392423
NSString *value = [copyData objectForKey:key];
393424
[extrasData setObject:value forKey:key];
394425
};
395-
426+
NSString *messageID = objectData[@"_j_msgid"]?objectData[@"_j_msgid"]:@"";
396427
if (extrasData.count > 0) {
397-
responseData = @{MESSAGE_ID:objectData[@"_j_msgid"],TITLE:title,CONTENT:content,EXTRAS:extrasData,NOTIFICATION_TYPE:notificationType};
428+
responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content,EXTRAS:extrasData,NOTIFICATION_EVENT_TYPE:notificationEventType};
398429
}
399430
else {
400-
responseData = @{MESSAGE_ID:objectData[@"_j_msgid"],TITLE:title,CONTENT:content,NOTIFICATION_TYPE:notificationType};
431+
responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content,NOTIFICATION_EVENT_TYPE:notificationEventType};
401432
}
402433
return responseData;
403434
}
404435

405-
-(NSDictionary *)convertCustomMessage:(NSNotification *)data {
436+
-(NSDictionary *)convertCustomMessage:(NSNotification *)data
437+
{
406438
NSDictionary *objectData = data.object;
407439
NSDictionary *responseData;
440+
NSString *messageID = objectData[@"_j_msgid"]?objectData[@"_j_msgid"]:@"";
441+
NSString *title = objectData[@"title"]?objectData[@"title"]:@"";
442+
NSString *content = objectData[@"content"]?objectData[@"content"]:@"";
408443
if(objectData[@"extras"]){
409-
responseData = @{MESSAGE_ID:objectData[@"_j_msgid"],CONTENT:objectData[@"content"],EXTRAS:objectData[@"extras"]};
444+
responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content,EXTRAS:objectData[@"extras"]};
410445
}else{
411-
responseData = @{MESSAGE_ID:objectData[@"_j_msgid"],CONTENT:objectData[@"content"]};
446+
responseData = @{MESSAGE_ID:messageID,TITLE:title,CONTENT:content};
412447
}
413448
return responseData;
414449
}
415450

416-
-(NSDictionary *)convertLocalMessage:(NSNotification *)data {
451+
-(NSDictionary *)convertLocalMessage:(NSNotification *)data
452+
{
417453
//NSLog(@"convertConnect 结果返回:%@", data);
418454
NSMutableDictionary *responseData = [[NSMutableDictionary alloc] init];
419455
return responseData;

0 commit comments

Comments
 (0)