iOS 極光推送接收通知
//通過通知啟動APP
NSDictionary *remoteUserInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteUserInfo) {//遠端通知啟動App
[selfmanageAPNSDataWith:remoteUserInfo];
}
//iOS 7.0 ~ iOS 10.0 系統接收遠端通知的方法
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(
fetchCompletionHandler:
(void (^)(UIBackgroundFetchResult))completionHandler {
if (application.applicationState !=UIApplicationStateActive) {
[selfmanageAPNSDataWith:userInfo];
}else{
}
[JPUSHServicehandleRemoteNotification:userInfo];
completionHandler(
}
//iOS 10.0 以上
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#pragma mark- JPUSHRegisterDelegate
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
// 需要執行這個方法,選擇是否提醒使用者,有Badge、Sound、Alert三種類型可以設定
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
[selfmanageAPNSDataWith:userInfo];
}
[JPUSHServicehandleRemoteNotification:userInfo];
completionHandler(); // 系統要求執行這個方法
}
#endif
#pragma mark - 處理遠端推送的資料
-(void)manageAPNSDataWith:(NSDictionary *)userInfo{
NSInteger flag = [[userInfo objectForKey:@"flag"] integerValue];
if (flag == 0) {//跳轉首頁
[selfpushToMVC];
}elseif (flag == 1){//跳轉詳情頁
SubscribMode *model = [[SubscribModealloc] init];
model.announcemenId = [NSStringstringWithFormat:@"%@",[userInfo objectForKey:@"id"]];
model.sourceId = [NSStringstringWithFormat:@"%@",[userInfo objectForKey:@"sourceId"]];
[selfpushToNoticeViewModel:model];
}
}