0

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 enabledRemoteNotificationTypes is only for remote notifications.

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

samwize
  • 25,675
  • 15
  • 141
  • 186

2 Answers2

1

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.

rdurand
  • 7,342
  • 3
  • 39
  • 72
0
- (BOOL) isLocalNotificationsEnable {
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {
        UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
        return (grantedSettings.types == UIUserNotificationTypeNone) ? NO : YES;
    }
    return NO;
}

Note: the if block is only require if you're targeting < iOS 8.0.

Hemang
  • 26,840
  • 19
  • 119
  • 186