使用iOS 10中的UNNotificationSettings检查通知types

如何使用UNNotificationSettings获取iOS 10中的通知types?

在以前的iOS上,我会使用这个:

 UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings]; Bool active = notificationSettings.types == UIUserNotificationTypeNone ? NO: YES; 

我希望你问这个

 UNUserNotificationCenter.currentNotificationCenter().getNotificationSettingsWithCompletionHandler{ (mySettings) in mySettings.alertStyle == .None } 

斯威夫特4

UNUserNotificationCenter.current().getNotificationSettings{ (mySettings) in mySettings.alertStyle == .none }

对于Objective-C

 [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { settings.alertStyle == UNAlertStyleNone }]