detect "Allow Notifications" is on/off for iOS8
Method enabledRemoteNotificationTypes
is deprecated since iOS8.
To check remote notifications status in iOS8 you can call
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
it will return NO if user disable notifications in Settings. Documentation on isRegisteredForRemoteNotifications
Or you can retrieve all current notification settings:
[[UIApplication sharedApplication] currentUserNotificationSettings];
Documentation on currentUserNotificationSettings
Swift 3+
let isRegisteredForLocalNotifications = UIApplication.shared.currentUserNotificationSettings?.types.contains(UIUserNotificationType.alert) ?? false
Swift 2.3
let isRegisteredForLocalNotifications = UIApplication.sharedApplication().currentUserNotificationSettings()?.types.contains(UIUserNotificationType.Alert) ?? false
I apologize for this answer/comment if it is in the wrong place. I am REALLY new at iOS programming and have never posted to stack overflow before. I think this should actually be a comment, but without a 50 rating I am not allowed. I also apologize if the explanation is somewhat rudimentary, but again, kind of new :).
I also wished to test for whether a user has changed what notifications are allowed/required by my app after the initial request. After trying to decipher the Apple documentation (the writers at Apple are either much smarter than I am, or the documentation is purposely obscure) and doing a bit of testing I tested for the value of
[[UIApplication sharedApplication] currentUserNotificationSettings].hash.
I believe that this returns a three bit hash value where bit one is for Banner notifications, bit 2 is for Sound notifications, and bit 3 is for Alert notifications.
So...
000 = 0 = no notifications.001 = 1 = only banner,010 = 2 = only sound,011 = 3 = sound and banner, no alert100 = 4 = only alert notificationsand so on until,111 = 7 = all notifications on.
This also shows 0 if Allow Notifications is turned off in the Settings app.Hope this helps.