在iOS10上多了一个UNUserNotificationCenter,可以在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
}
然后实现方法
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionBadge);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
NSDictionary *userinfo = response.notification.request.content.userInfo;
if (userinfo && [userinfo isKindOfClass:[NSDictionary class]]) {
}
}
使用时最好判断一下版本
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_0
官方文档:
https://developer.apple.com/reference/usernotifications/unusernotificationcenter
WWDC16 Session707:
Introduction to Notifications
WWDC16 Session708:
Advanced Notifications
WWDC16 Session724:
What's New in the Apple Push Notification Service