samwize samwize - 2 years ago 171
iOS Question

How to check if Local Notification is enabled/disabled?

I understand we can check if a user has enabled/disabled Remote Notification with this code:

[[UIApplication sharedApplication] enabledRemoteNotificationTypes]

But what about checking for Local Notification?

I don't find a corresponding property for local notification types, and I have verified that
is only for remote notifications.

And we all know, users can edit their Notification settings, which will affect both remote and local.

Answer Source

I'm not sure, but I don't think you can access this information.

One way you can check if the user has notifications enabled for your app is to send yourself a local notification with a 1 second delay :

UILocalNotification *testNotification = [[UILocalNotification alloc] init]; 
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
localNotification.alertBody = @"Test notification";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

And check if you catch it in :

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification) {

    // If you get here, notifications are enabled

All there is left is add info (e.g in localNotification.userInfo) so you can know in didReceiveLocalNotification: if you are handling your test notification, or if it's a "real" notification.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download