iOS10推送项目配置
来源:互联网 发布:中宣部知乎 编辑:程序博客网 时间:2024/06/05 06:25
iOS10推送新增了UserNotifications Framework,使用起来其实很简单。
只是在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, import 新框架
添加新的框架 UserNotifications.framework
2,导入头文件#import <UserNotifications/UserNotifications.h>
3,注册远程通知
- (void)setRemoteNotifications {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];
} else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 && [[UIDevice currentDevice].systemVersion doubleValue] < 10.0){//iOS8-iOS10
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {//iOS8以下
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
}
}
4 项目配置
- iOS10推送项目配置
- iOS10 推送最新配置
- 项目中友盟推送适配iOS10
- iOS10 推送
- iOS10 关于推送
- iOS10注册极光推送
- iOS10 推送证书问题
- iOS10 本地推送机制
- iOS10 消息推送
- iOS10注册极光推送
- iOS10 注册极光推送
- iOS10 推送详解
- iOS10以后的推送
- iOS10 推送证书问题
- ios10 本地推送
- iOS10推送 本地通知
- iOS10推送必看
- iOS10 推送通知整理
- 数据库增删改命令 分类笔记
- linux中的动态、静态库
- Record Locks
- 传统IO socket
- select 优化socket回射服务器
- iOS10推送项目配置
- 监控线上服务器运行情况脚本
- unsigned类型需要注意的事项
- C++“准”标准库Boost学习指南(9):Boost.Bind
- combobox下拉框级联并且每一个框默认选择第一个值使用onLoadSuccess——easyUI
- reinforcement learning,增强学习:Policy Evaluation,Policy Iteration,Value Iteration,Dynamic Programming f
- 搭建Struts2开发环境
- “九头虫”病毒技术分析报告
- PowerDesigner v16.5