UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
notificationTypes
has the integer code which will help us to find what are the remote notification enabled. For that, we need to understand the UIRemoteNotificationType
,
typedef enum {
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2,
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
} UIRemoteNotificationType;
According to the Bitwise left shift calculation, following are the values,
- UIRemoteNotificationTypeNone = 0
- UIRemoteNotificationTypeBadge = 1
- UIRemoteNotificationTypeSound = 2
- UIRemoteNotificationTypeAlert = 4
- UIRemoteNotificationTypeNewsstandContentAvailability = 8
Following code will help us to find what are the remote notification enabled for your app,
if (notificationTypes == UIRemoteNotificationTypeNone) {
// Do what ever you need to here when notifications are disabled
NSLog(@"User doesn't want to receive push-notifications");
} else if (notificationTypes == UIRemoteNotificationTypeBadge) {
// Badge only
NSLog(@"Badges Only");
} else if (notificationTypes == UIRemoteNotificationTypeAlert) {
// Alert only
NSLog(@"Alerts only");
} else if (notificationTypes == UIRemoteNotificationTypeSound) {
// Sound only
NSLog(@"Sound Only");
}
else if (notificationTypes == UIRemoteNotificationTypeNewsstandContentAvailability) {
// NewsstandContentAvailability only
NSLog(@"NewsstandContentAvailability Only");
}else if (notificationTypes == 5)//Badge(1)+Alert(4)=5 {
// Badge & Alert
NSLog(@"Badges and Alert");
} else if (notificationTypes == 3)//Badge(1)+Sound(2)=3 {
// Badge & Sound
NSLog(@"Badges and Sound");
} else if (notificationTypes == 6)//Alert(4)+Sound(2)=6 {
// Alert & Sound
NSLog(@"Alert and Sound");
} else if (notificationTypes == 7)//Badge(1)+Alert(4)+Sound(2)=7 {
// Badge, Alert & Sound
NSLog(@"Badge, Alert & Sound");
}
else if (notificationTypes == 10)//Sound(2)+NewsstandContentAvailability(8)=10 {
// Sound & NewsstandContentAvailability
NSLog(@"Sound & NewsstandContentAvailability");
}
Note: I haven't write all possible if-else statements. Please add according to your need.
Hope this will help you.