Do Local Notifications need user permission on iOS?
Asked Answered
B

5

28

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.

Bunn answered 16/4, 2013 at 23:18 Comment(0)
A
6

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

Alforja answered 19/12, 2014 at 4:28 Comment(0)
D
21

Yes, in iOS8, local notifications do require permissions.

The documentation for registerUserNotificationSettings: stipulates that

If your app displays alerts, play sounds, or badges its icon while in the background, you must call this method during your launch cycle to request permission to alert the user in those ways. Typically, you make this request if your app uses local or push notifications to alert the user to new information involving your app.

It is recommended that you call this method before you schedule any local notifications or register with the push notification service.

Dynah answered 30/10, 2014 at 15:9 Comment(0)
B
12

It looks like local notifications do not need any user permission. The Permission dialog just shows up for the Push Notifications. I am able to schedule/cancel local notifications without any user permission.

Bunn answered 16/5, 2013 at 22:2 Comment(2)
same here: looking at the new iOS10 UserNotificationsCenter - local notifications are scheduled without any access point.Maltose
@Maltose Are you sure? Seems like it forces premessionsCarminecarmita
A
6

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

Alforja answered 19/12, 2014 at 4:28 Comment(0)
A
4

Apple's documentation for presentLocalNotificationNow and scheduleLocalNotification says,

Prior to scheduling any local notifications, you must call the registerUserNotificationSettings: method to let the system know what types of alerts, if any, you plan to display to the user.

So I am not sure how others in this page are saying Local Notifications do not need User Permissions.

Checkout this other discussion on the same topic:

Ask for User Permission to Receive UILocalNotifications in iOS 8

Adame answered 17/2, 2016 at 21:53 Comment(1)
This seems to be enforced in iOS 9 and above.Aromatic
P
2

Yes, that's correct. Local notifications do not need any OS permissions. However, as a good practice, I'd suggest giving an opt-out option for the user in such cases from your application. This would work well in two ways:

  1. An annoyed user, getting frustrated because of seeing local notification yet time & again, not knowing the difference between Push/Local notification might leave a bad review on the app store.
  2. Its always a good practice to provide flags to turn ON/OFF such functionality for a given user.
Panter answered 2/9, 2014 at 9:1 Comment(1)
Agreed ! Our app has hat option :)Bunn

© 2022 - 2024 — McMap. All rights reserved.