I am enabling push notification for my application. How can we read the flags for notification in "Settings" app when my app is Running. For some reasons, I need to know whether a particular notification (alert, sound, badge) is set to ON/OFF.
Please guide.
Try evoking this method [[UIApplication sharedApplication] enabledRemoteNotificationTypes]
It will return a UIRemoteNotificationType which you can work with to determine what is available.
UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
Now, status can be looked at as an int using NSLog(@"status = ", status);
, to which we can determine exactly what is on. But to do this we need to understand UIRemoteNotificationType.
typedef enum {
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2,
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
} UIRemoteNotificationType;
Without going into much detail, what you basically need to walk away from this knowing is that ...
Let's say you want to know if badges/sound/alerts are all on. The UIRemoteNotificationType (status if you are playing along) should come out to be 7.
Now, lets work backwards. Lets say that status == 5
. There is only one configuration of settings that can give us this value, and that is if badges and alerts are on (badges add 1, alerts add 4, total is 5) and sound is off.
What if status == 6
? Again, there is only one configuration of settings that will return this number, and that is if alerts and sound are both on, while badges are off.
Using IF statements, we can do something like
If (status == 5)
{
NSLog(@"User has sound alerts disabled");
[self fireThatSpecialMethod];
}
To run a set block of code, or fire a particular method for when sound is disabled, but everything else is on. Anyways, hope this response is helpful to people!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With