Why does UIUserNotificationType.None return true in the current settings when user permission is granted?

I am writing a method to check if the current user settings consist of certain types of notifications.

When checking to see if the current settings of UIUserNotificationsType.None, it returns true for both permission and failure. Does anyone know why this is?

func registerForAllNotificationTypes() { registerNotificationsForTypes([.Badge, .Alert, .Sound]) } func registerNotificationsForTypes(types:UIUserNotificationType) { let settings = UIUserNotificationSettings.init(forTypes:types, categories: nil) UIApplication.sharedApplication().registerUserNotificationSettings(settings) } func isRegisteredForAnyNotifications() -> Bool { let currentSettings = UIApplication.sharedApplication().currentUserNotificationSettings() print(currentSettings) print((currentSettings?.types.contains(.Alert))!) print((currentSettings?.types.contains(.Badge))!) print((currentSettings?.types.contains(.Sound))!) print((currentSettings?.types.contains(.None))!) return (currentSettings?.types.contains(.Alert))! //Just testing .Alert for now } 

When permission is enabled:

Optional(<UIUserNotificationSettings: 0x7fabdb719360; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>) true true true true

When permission is disabled:

Optional(<UIUserNotificationSettings: 0x7f96d9f52140; types: (none);>) false false false true

+6
source share
1 answer

The funny thing is, it just confirms that 0 contains 0 :) Take a look at the enum definition for UIUserNotificationsType: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIUserNotificationSettings_class/index.html#// apple_ref / c / tdef / UIUserNotificationType

 struct UIUserNotificationType : OptionSetType { init(rawValue rawValue: UInt) static var None: UIUserNotificationType { get } static var Badge: UIUserNotificationType { get } static var Sound: UIUserNotificationType { get } static var Alert: UIUserNotificationType { get } } 

But this is more clearly visible in Objective-C:

 typedef enum UIUserNotificationType : NSUInteger { UIUserNotificationTypeNone = 0, UIUserNotificationTypeBadge = 1 << 0, UIUserNotificationTypeSound = 1 << 1, UIUserNotificationTypeAlert = 1 << 2, } UIUserNotificationType; 
+2
source

All Articles