diff --git a/ionic/example/src/pages/home/home.ts b/ionic/example/src/pages/home/home.ts index 8d725a7..22b1577 100644 --- a/ionic/example/src/pages/home/home.ts +++ b/ionic/example/src/pages/home/home.ts @@ -43,7 +43,7 @@ export class HomePage { } else { content = event.aps.alert; } - console.log('Receive notification: ' + content); + alert('Receive notification: ' + JSON.stringify(event)); }, false); document.addEventListener('jpush.openNotification', (event: any) => { @@ -53,7 +53,8 @@ export class HomePage { } else { content = event.aps.alert; } - alert('Open notification: ' + content); + // alert('Open notification: ' + content); + alert('open notification: ' + JSON.stringify(event)); }, false); document.addEventListener('jpush.receiveLocalNotification', (event: any) => { diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index 301638e..b4943d9 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -137,19 +137,38 @@ NSDictionary *_launchOptions; } -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{ - NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; - [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; - completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); + NSMutableDictionary *userInfo = @[].mutableCopy; + + if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { + userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; + } else { + UNNotificationContent *content = notification.request.content; + userInfo = @{@"content": content.body, + @"badge": content.badge, + @"extras": content.userInfo + }; + } + + [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; + completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); } -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{ - NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo]; - @try { - [userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"]; - } @catch (NSException *exception) { } - [userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"]; - [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]]; - completionHandler(); + UNNotification *notification = response.notification; + NSMutableDictionary *userInfo = nil; + + if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { + userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; + } else { + UNNotificationContent *content = notification.request.content; + userInfo = [NSMutableDictionary dictionaryWithDictionary:@{@"content": content.body, + @"badge": content.badge, + @"extras": content.userInfo + }]; + } + userInfo[@"actionIdentifier"] = response.actionIdentifier; + [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]]; + completionHandler(); } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {