概述
//通过通知启动APP
NSDictionary *remoteUserInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteUserInfo) {//远程通知启动App
[self manageAPNSDataWith:remoteUserInfo];
}
//iOS 7.0 ~ iOS 10.0 系统接收远程通知的方法
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:
(void (^)(UIBackgroundFetchResult))completionHandler {
if (application.applicationState !=UIApplicationStateActive) {
[self manageAPNSDataWith:userInfo];
}else{
}
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
//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.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[self manageAPNSDataWith:userInfo];
}
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(); // 系统要求执行这个方法
}
#endif
#pragma mark - 处理远程推送的数据
-(void)manageAPNSDataWith:(NSDictionary *)userInfo{
NSInteger flag = [[userInfo objectForKey:@"flag"] integerValue];
if (flag == 0) {//跳转首页
[self pushToMVC];
}else if (flag == 1){//跳转详情页
SubscribMode *model = [[SubscribMode alloc] init];
model.announcemenId = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"id"]];
model.sourceId = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"sourceId"]];
[self pushToNoticeViewModel:model];
}
}
最后
以上就是虚拟黄豆为你收集整理的iOS 极光推送接收通知的全部内容,希望文章能够帮你解决iOS 极光推送接收通知所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复