#pragma mark *** JPUSHRegisterDelegate ***
// >= iOS 10 Support , App Forground
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
// 收到推送消息,追踪"App 消息推送"事件
[AnalysysAgent trackCampaign:userInfo isClick:NO userCallback:^(id campaignInfo) {
NSLog(@"此处可根据需要处理数据 : %@",campaignInfo);
}];
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
}
// iOS 10 Support, App Background
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
// 点击通知栏打开消息,记录"App 点击通知"事件
[AnalysysAgent trackCampaign:userInfo isClick:YES userCallback:^(id campaignInfo) {
NSLog(@"此处可根据需要处理数据 : %@",campaignInfo);
}];
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler();
}
// >= iOS 7 <iOS 10
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
[self handleRemoteNotificationWithApplication:application userInfo:userInfo];
}
// < iOS 7
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[JPUSHService handleRemoteNotification:userInfo];
[self handleRemoteNotificationWithApplication:application userInfo:userInfo];
}