#pragma mark iOS 10 前台收到通知(远程推送和本地通知)
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
/// iOS10处理远程推送
[JPUSHServicehandleRemoteNotification:userInfo];
pushDic = userInfo;
/// 应用处于前台收到推送的时候转成本地通知 ===========================
UILocalNotification *notification = [[UILocalNotificationalloc] init];
notification.alertTitle =@"哈哈哈哈哈";
notification.alertBody =@"aaaaaa";
notification.userInfo = userInfo;
[[UIApplicationsharedApplication] presentLocalNotificationNow:notification];
}else{
/// 应用处于前台收到本地通知不会出现在通知中心 借用极光推送的方法将本地通知添加到通知栏 ==============================
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
// 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
}
/// 程序运行于前台,后台 或杀死 点击推送通知 都会走这个方法
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
// Required
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
[JPUSHServicehandleRemoteNotification:userInfo];
/// 杀死,后台点击通知栏 处理远程推送的跳转
[selfreciveNotification:userInfo];
}else{
/// 前台运行时 转的本地通知 直接通知栏弹窗进行跳转处理
[selfreciveNotification:userInfo];
}
completionHandler(); // 系统要求执行这个方法
}