Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Notification flag in "Settings" application inside my iPhone application

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.

like image 346
Abhinav Avatar asked Mar 22 '11 23:03

Abhinav


1 Answers

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 ...

  • If badges are on, add 1
  • If sound is on, add 2
  • If alerts are on, add 4
  • If Newsstand Content is available, add 8 (I'm not going to worry about this guy)

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!

like image 197
NicholasTGD Avatar answered Oct 28 '22 12:10

NicholasTGD