IOS 推送适配

iOS 10 推送适配

1.TARGETS—BuildPhases—Link Binary With Libraries— 添加 UserNotifications.framework;

2.AppDelegate 中导入 #import并且继承 UNUserNotificationCenterDelegate

3.注册推送:判断当前手机版本如果为iOS 10或者以上

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;//如果客户同意使用则实现代理
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {

if (granted) {

//客户允许APP使用推送

}

}];

4.实现代理方法:


- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler</code>

//应用在前台收到通知}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

//点击通知进入应用}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容