使用iOS 10中的UNNotificationSettings检查通知类型

Meh*_*han 7 cocoa-touch ios ios10 usernotifications

如何UNNotificationSettings在iOS 10中使用获取通知类型?

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

UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

Bool active = notificationSettings.types == UIUserNotificationTypeNone ? NO: YES;
Run Code Online (Sandbox Code Playgroud)

Aru*_*un_ 7

我希望你问这个问题

UNUserNotificationCenter.currentNotificationCenter().getNotificationSettingsWithCompletionHandler{ (mySettings) in  mySettings.alertStyle == .None }
Run Code Online (Sandbox Code Playgroud)

斯威夫特4

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

对于Objective-C

[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
    settings.alertStyle == UNAlertStyleNone
}]
Run Code Online (Sandbox Code Playgroud)