美文网首页
iOS 10 中的推送适配问题

iOS 10 中的推送适配问题

作者: 夜深有雨 | 来源:发表于2016-09-19 17:37 被阅读0次

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

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

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

UNUserNotificationCenter*center = [UNUserNotificationCentercurrentNotificationCenter];

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

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

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

//点击通知进入应用}

相关文章

网友评论

      本文标题:iOS 10 中的推送适配问题

      本文链接:https://www.haomeiwen.com/subject/tevqhttx.html