1.TARGETS—BuildPhases—Link Binary With Libraries— 添加 UserNotifications.framework;
2.AppDelegate 中導(dǎo)入#import 并且繼承UNUserNotificationCenterDelegate
3.注冊推送:判斷當(dāng)前手機(jī)版本如果為iOS 10或者以上
UNUserNotificationCenter*center = [UNUserNotificationCentercurrentNotificationCenter];
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
//應(yīng)用在前臺收到通知}
- (void)userNotificationCenter:(UNUserNotificationCenter*)center didReceiveNotificationResponse:(UNNotificationResponse*)response withCompletionHandler:(void(^)())completionHandler {
//點(diǎn)擊通知進(jìn)入應(yīng)用}