Do Local Notifications need user permission on iOS? - swift

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.

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.

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.

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

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

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:
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.
Its always a good practice to provide flags to turn ON/OFF such functionality for a given user.

Related

ios unregisterForRemoteNotifications does not work

I am trying to get my device unregistered from the remote notification services in my app, so I tried to use [[UIApplication sharedApplication] unregisterForRemoteNotifications]. But this does not work. My app still shows up on the notifications section of my iPhone's settings app. Is there any other way I can do this?
It is still there but it won't receive any notifications. That is the default behavior, once you registered your app will remain in the notification center and it will be activated/ deactivated when you register/unregister for remote notifications.
Unregister function is not related to iOS app setting.
Only if you turn on the setting and register notification by function, you can get the notification successfully.
If even one of them is off, you should not receive any notification.

Knowing if an app is authorized to receive push notifications on-the-fly

Consider this situation. The app runs and application:didRegisterForRemoteNotificationsWithDeviceToken: receives information that the app is authorized to receive push notifications.
User puts app to background and removes app's authorization to receive notifications on the device's configuration.
User runs app again. Returning from background, the app still thinks it has authorization to receive push notifications. Neither application:didRegisterForRemoteNotificationsWithDeviceToken: or application:didFailToRegisterForRemoteNotificationsWithError: receives anything at this point.
Is there a way to know at any given point if an app has authorization to receive push notifications (reading something from device's notification preferences)?
thanks.
You can check for [[UIApplication sharedApplication] enabledRemoteNotificationTypes] each time the app returns from background.
See: iOS - Check for push notification support in the app
Once I have verified that the user has it disabled is there a way to programmatically direct the user to the notification settings on the device's configuration?
No for newer iOS versions. According to Navigate to settings screen in iphone and iOS Launching Settings -> Restrictions URL Scheme, you can use -[[UIApplication sharedApplication] openURL:] to navigate to settings screen, but only on devices running iOS version 5.0 and prior.

Notifications - ios

I want to get all the notifications related to my app which is stored in the notification center of the iPhone. How can I get this ?
You can use [[UIApplication sharedApplication] scheduledLocalNotifications] to get the complete list of scheduled notifications. Hope it'll help. Enjoy Coding.
For Local Notification, you can get all the notifications related to that app using,
[[UIApplication sharedApplication] scheduledLocalNotifications]
But for Push notification, i dont think its possible, but the another way to achieve this is, if the user views/select a push notification, then you should store it in your local.
it was described already the Local and Push notifications in previous 2 answers.
What else is stored into notification center can be a good example here:
It is intended to be used as communication between UI elements, screens, background. But can be used for other "almost legal" stuff, which will not bypass the Apple code review: private API, hacking and such if is started to use in "not as intended by Apple" :)
It is in the notification center and it is a notification too.
I am sure not about this are you asking, because of:
"related to my app"
this is related to a component of your app.

Can I change APN settings from within app?

My app, makes use of APN services. At first launch, it sends a
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
request. This triggers a system alert with permission request. No matter what the user chooses, it will be possible to change it from Settings, notification pane. The app gets the notifications and everything seems to work fine.
Now I have been asked to place a switch inside the app to activate/deactivate push notifications from inside the app.
I don't think this is possible, but before answering I'd like to get a confirmation.
Is there a way to access (read and/or write) notification permissions related to a specific app from within the app itself (just like app defaults preferences)?
Is there a way to delete the app from the list of the apps which need push notifications once it has been added due to the initial request?
No, as it is a system setting relating to your app rather than an app setting. Otherwise any app could automatically enable all its notifications whenever launched, which would cause havoc.
Edit:
You can read your app's permissions using UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; and then performing a bitwise and operation with the different types to see which are enabled.

alert for allow or dont allow Apple push notification in iphone application

I am using Apple Push Notification in my application.
when my application is installed on device i want application to ask user if they want allow application to use notification or not, how can i implement so?
something like this application.
Thanks.
You don't need to do any extra work for that. Just configure your app for push notifications and call:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: types];
This happens automatically when an app asks to register itself for push notifications, just as it does when an app first asks for the device's location. You don't need to do anything special beyond the -registerForRemoteNotificationTypes: call (as Max mentioned) which you have to make anyway.