From 4780eafb72c7898ca963df40e8fdca35d3760b9d Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Thu, 14 Dec 2017 15:36:43 +0800 Subject: [PATCH] adjust ios remote notification formate --- src/ios/Plugins/AppDelegate+JPush.m | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index cb68d82..fcc7026 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -44,7 +44,8 @@ NSDictionary *_launchOptions; if (notification.userInfo) { if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { - [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[notification.userInfo toJsonString]]; + [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification + jsString:[[self jpushFormatAPNSDic: notification.userInfo[UIApplicationLaunchOptionsRemoteNotificationKey]] toJsonString]]; } if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) { @@ -82,6 +83,23 @@ NSDictionary *_launchOptions; [JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]]; } +- (NSMutableDictionary *)jpushFormatAPNSDic:(NSDictionary *)dic { + NSMutableDictionary *extras = @{}.mutableCopy; + for (NSString *key in dic) { + if([key isEqualToString:@"_j_business"] || + [key isEqualToString:@"_j_msgid"] || + [key isEqualToString:@"_j_uid"] || + [key isEqualToString:@"actionIdentifier"] || + [key isEqualToString:@"aps"]) { + continue; + } + extras[key] = dic[key]; + } + NSMutableDictionary *formatDic = dic.mutableCopy; + formatDic[@"extras"] = extras; + return formatDic; +} + -(void)registerForRemoteNotification{ if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) { #ifdef NSFoundationVersionNumber_iOS_9_x_Max @@ -130,7 +148,8 @@ NSDictionary *_launchOptions; default: break; } - [JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]]; + + [JPushPlugin fireDocumentEvent:eventName jsString:[[self jpushFormatAPNSDic:userInfo] toJsonString]]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ completionHandler(UIBackgroundFetchResultNewData); }); @@ -140,7 +159,7 @@ NSDictionary *_launchOptions; NSMutableDictionary *userInfo = @[].mutableCopy; if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { - userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; + userInfo = [self jpushFormatAPNSDic:notification.request.content.userInfo]; } else { UNNotificationContent *content = notification.request.content; userInfo = [NSMutableDictionary dictionaryWithDictionary:@{@"content": content.body, @@ -159,7 +178,7 @@ NSDictionary *_launchOptions; NSMutableDictionary *userInfo = nil; if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { - userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; + userInfo = [self jpushFormatAPNSDic:notification.request.content.userInfo]; } else { UNNotificationContent *content = notification.request.content; userInfo = [NSMutableDictionary dictionaryWithDictionary:@{@"content": content.body,