fix local notification event in ios 10

This commit is contained in:
huangminlinux 2017-12-12 17:00:28 +08:00
parent 9ea65add1f
commit f50a8ea5c7
2 changed files with 32 additions and 12 deletions

View File

@ -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) => {

View File

@ -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 {