时间:2021-05-20
IOS10 远程推送适配
iOS10推送新增了UserNotifications Framework,使用起来其实很简单。
建议看看极光推送的Demo,里面写的更详细。
只是在iOS10以上系统上点击通知栏,回调方法不再走原来的这两个方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {}而是在前台的时候回调
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler从后台进入的时候回调
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler直接说怎么用吧:
1,导入头文件
#ifdef NSFoundationVersionNumber_iOS_9_x_Max#import <UserNotifications/UserNotifications.h>#endif2,注册通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中
if (iOS10) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) { if (!error) { NSLog(@"succeeded!"); } }]; } else if (iOS8_9){//iOS8-iOS9 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; } else {//iOS8以下 [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; }3,回调方法中,获取通知数据
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { NSDictionary *userInfo = response.notification.request.content.userInfo; //消息处理 if([request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { //判断为远程推送 }else { // 判断为本地通知 }}4,对于本地通知没有什么变化依然会回调
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
iOS10正式版发布之后,网上各种适配XCode8以及iOS10的文章满天飞。但对于iOS10适配远程推送的文章却不多。iOS10对于推送的修改还是非常大的,新
iOS10系统的设备开始推送了iOS10的正式版系统。iOS版微信也同步更新适配了全新的iOS10系统。那么ios10微信显示名字怎么办?ios10微信显示人名
苹果6月份开发者大会上将推出ios10预览版,很多用户关心该系统适配机型。今天小编就为大家带来苹果ios10支持设备介绍,一起看看吧! ios10开发者预
今日凌晨,苹果正式推送了iOS10正式版系统更新,其中iOS10就新增了一个“轻触打开”,所谓功能,都是有利又有弊的,那么iOS10轻触
今日凌晨,苹果正式向广大苹果设备用户推送了iOS10正式版系统更新,其中iOS10就新增了一个“照片回忆”功能。那么iOS10照片回忆怎