iOS 10 推送適配
1.TARGETS—BuildPhases—Link Binary With Libraries— 添加 UserNotifications.framework;
2.AppDelegate 中導(dǎo)入 #import并且繼承 UNUserNotificationCenterDelegate
3.注冊(cè)推送:判斷當(dāng)前手機(jī)版本如果為iOS 10或者以上
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;//如果客戶同意使用則實(shí)現(xiàn)代理
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
//客戶允許APP使用推送
}
}];
4.實(shí)現(xiàn)代理方法:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler</code>
//應(yīng)用在前臺(tái)收到通知}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
//點(diǎn)擊通知進(jìn)入應(yīng)用}