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,9 @@ @implementation RCTJPushModule
5152
5253RCT_EXPORT_MODULE (JPushModule);
5354
54- - (id )init {
55+ - (id )init
56+ {
57+ NSLog (@" xxx init" );
5558 self = [super init ];
5659 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter ];
5760
@@ -95,7 +98,6 @@ - (id)init {
9598 return self;
9699}
97100
98-
99101RCT_EXPORT_METHOD (setDebugMode: (NSDictionary *)options)
100102{
101103 BOOL isDebug = false ;
@@ -107,6 +109,14 @@ - (id)init {
107109 }
108110}
109111
112+ RCT_EXPORT_METHOD (loadJS)
113+ {
114+ NSMutableArray *list = [RCTJPushEventQueue sharedInstance ]._notificationQueue ;
115+ if (list.count ) {
116+ [self sendApnsNotificationEventByDictionary: list[0 ]];
117+ }
118+ }
119+
110120RCT_EXPORT_METHOD (getRegisterId:(RCTResponseSenderBlock) callback)
111121{
112122 [JPUSHService registrationIDCompletionHandler: ^(int resCode, NSString *registrationID) {
@@ -116,7 +126,6 @@ - (id)init {
116126 }];
117127}
118128
119-
120129// tag
121130RCT_EXPORT_METHOD (addTags:(NSDictionary *)params)
122131{
@@ -298,13 +307,29 @@ - (void)sendConnectEvent:(NSNotification *)data {
298307 completion: NULL ];
299308}
300309
310+ // APNS通知消息
301311- (void )sendApnsNotificationEvent : (NSNotification *)data
302312{
303313 NSDictionary *responseData = [self convertApnsMessage: data];
304314 [self .bridge enqueueJSCall: @" RCTDeviceEventEmitter"
305315 method: @" emit"
306316 args: @[NOTIFICATION_EVENT, responseData]
307317 completion: NULL ];
318+ if ([RCTJPushEventQueue sharedInstance ]._notificationQueue .count ){
319+ [[RCTJPushEventQueue sharedInstance ]._notificationQueue removeAllObjects ];
320+ }
321+ }
322+
323+ - (void )sendApnsNotificationEventByDictionary : (NSDictionary *)data
324+ {
325+ NSDictionary *responseData = [self convertApnsMessage: data];
326+ [self .bridge enqueueJSCall: @" RCTDeviceEventEmitter"
327+ method: @" emit"
328+ args: @[NOTIFICATION_EVENT, responseData]
329+ completion: NULL ];
330+ if ([RCTJPushEventQueue sharedInstance ]._notificationQueue .count ){
331+ [[RCTJPushEventQueue sharedInstance ]._notificationQueue removeAllObjects ];
332+ }
308333}
309334
310335// 自定义消息
@@ -356,10 +381,18 @@ -(NSDictionary *)convertConnect:(NSNotification *)data {
356381 return responseData;
357382}
358383
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;
384+ -(NSDictionary *)convertApnsMessage : (id )data
385+ {
386+ NSNotificationName notificationName;
387+ NSDictionary *objectData;
388+ if ([data isKindOfClass: [NSNotification class ]]){
389+ notificationName = [(NSNotification *)data name ];
390+ objectData = [(NSNotification *)data object ];
391+ }else if ([data isKindOfClass: [NSDictionary class ]]){
392+ notificationName = J_APNS_NOTIFICATION_OPENED_EVENT;
393+ objectData = data;
394+ }
395+ NSString *notificationEventType = ([notificationName isEqualToString: J_APNS_NOTIFICATION_OPENED_EVENT])?NOTIFICATION_OPENED:NOTIFICATION_ARRIVED;
363396 id alertData = objectData[@" aps" ][@" alert" ];
364397 NSString *title = @" " ;
365398 NSString *content = @" " ;
@@ -394,15 +427,16 @@ -(NSDictionary *)convertApnsMessage:(NSNotification *)data{
394427 };
395428
396429 if (extrasData.count > 0 ) {
397- responseData = @{MESSAGE_ID:objectData[@" _j_msgid" ],TITLE:title,CONTENT:content,EXTRAS:extrasData,NOTIFICATION_TYPE:notificationType };
430+ responseData = @{MESSAGE_ID:objectData[@" _j_msgid" ],TITLE:title,CONTENT:content,EXTRAS:extrasData,NOTIFICATION_EVENT_TYPE:notificationEventType };
398431 }
399432 else {
400- responseData = @{MESSAGE_ID:objectData[@" _j_msgid" ],TITLE:title,CONTENT:content,NOTIFICATION_TYPE:notificationType };
433+ responseData = @{MESSAGE_ID:objectData[@" _j_msgid" ],TITLE:title,CONTENT:content,NOTIFICATION_EVENT_TYPE:notificationEventType };
401434 }
402435 return responseData;
403436}
404437
405- -(NSDictionary *)convertCustomMessage : (NSNotification *)data {
438+ -(NSDictionary *)convertCustomMessage : (NSNotification *)data
439+ {
406440 NSDictionary *objectData = data.object ;
407441 NSDictionary *responseData;
408442 if (objectData[@" extras" ]){
@@ -413,7 +447,8 @@ -(NSDictionary *)convertCustomMessage:(NSNotification *)data {
413447 return responseData;
414448}
415449
416- -(NSDictionary *)convertLocalMessage : (NSNotification *)data {
450+ -(NSDictionary *)convertLocalMessage : (NSNotification *)data
451+ {
417452 // NSLog(@"convertConnect 结果返回:%@", data);
418453 NSMutableDictionary *responseData = [[NSMutableDictionary alloc ] init ];
419454 return responseData;
0 commit comments