Reputation: 9273
in iOS 7 i can retrieve the notification type that the user have enabled in this way:
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
but on iOS 8 i can't do this, because i get this in the console:
enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.
i have found a way to check if the notification are enabled on iOS 8:
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]
but how i can retrieve of what type of notification are enabled like in iOS 7?
Upvotes: 1
Views: 1420
Reputation: 3886
I had the same problem and I found out that the types property is basically a bitmask. Here is how you can extract the informations. My example is in Swift though.
let settings = UIApplication.sharedApplication().currentUserNotificationSettings()
if settings.types.rawValue & UIUserNotificationType.Alert.rawValue == UIUserNotificationType.Alert.rawValue
{
// can receive alert!
}
else
{
// if the user is not even able to receive alerts, show him a hint on how to reenable notifications in system settings
}
if settings.types.rawValue & UIUserNotificationType.Badge.rawValue == UIUserNotificationType.Badge.rawValue
{
// can receive badge!
}
if settings.types.rawValue & UIUserNotificationType.Sound.rawValue == UIUserNotificationType.Sound.rawValue
{
// can receive sound!
}
Upvotes: 0
Reputation: 212
According to developer.apple.com you may use this UIApplication's method:
- (UIUserNotificationSettings *)currentUserNotificationSettings
and then check notification types by using:
@property (nonatomic, readonly) UIUserNotificationType types;
So it will be something like this:
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
UIUserNotificationType types = settings.types;
Upvotes: 2