Search code examples
swiftnotificationslocaluilocalnotification

Do Local Notifications need user permission on iOS?


I am using UILocalNotification in my app to schedule notifications. The notifications work fine and show up when I want them to. I dont have an issue with that. I am NOT doing any remote/push notifications.

What got me wondering is that I never saw the famous permissions dialog that you usually see for push notifications in several app. I even reset my device and ran my app. That still didn't cause the permission dialog to show up.

Does this permission dialog not show up if your app is using only local notifications or am I not implementing some method that actually causes the app to ask for this permission?

I know I could implement my own dialog after the app started that asked the user for this permission but I was hoping that Apple took care of that, especially since it treats remote and local notifications the same in the Settings app.


Solution

  • NOTE: this includes push notifications / remote notifications

    when using Xcode6 with iOS7 or iOS8 Test when registerUserNotificationSettings: API is available at runtime.

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {  
        UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];  
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];  
        [[UIApplication sharedApplication] registerForRemoteNotifications];  
    } else {  
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];  
    }  
    

    Thanks to http://corinnekrych.blogspot.ae/2014/07/how-to-support-push-notification-for.html