Check if Local Notifications are enabled in IOS 8

Jacob Richman picture Jacob Richman · Sep 26, 2014 · Viewed 22.6k times · Source

I've looked all over the internet for how to create local notifications with IOS 8. I found many articles, but none explained how to determine if the user has set "alerts" on or off. Could someone please help me!!! I would prefer to use Objective C over Swift.

Answer

Bhumit Mehta picture Bhumit Mehta · Sep 26, 2014

You can check it by using UIApplication 's currentUserNotificationSettings

if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]){ // Check it's iOS 8 and above
    UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

    if (grantedSettings.types == UIUserNotificationTypeNone) {
        NSLog(@"No permiossion granted");
    }
    else if (grantedSettings.types & UIUserNotificationTypeSound & UIUserNotificationTypeAlert ){
        NSLog(@"Sound and alert permissions ");
    }
    else if (grantedSettings.types  & UIUserNotificationTypeAlert){
        NSLog(@"Alert Permission Granted");
    }
}

Hope this helps , Let me know if you need more info