How to access notification settings programmatically - iphone

My application uses push notifications. It would be nice to show notifications status on the UI. Is it possible to read notification settings from iPhone settings application like my own application settings in settings bundle?

[[UIApplication sharedApplication] enabledRemoteNotificationTypes] will give you a bitmask showing whether badges, sounds, and/or alerts are enabled for your app. (Note that this setting only affects remote notifications; local notifications are unaffected).
Otherwise, as rckoenes points out, you can't access any settings in your app.

No you can't access general settings from your app.

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.

'Alert Style' option missing from Notifications settings

I have set up an iOS app with push notifications.The problem is that the app ignores notifications while not being active or more precisely banners don't show up.One stranger thing is that the 'Alert Style' option is missing.
I wonder whether the .entitlements file is necessary and should I define something there.Except for that I think all settings are made correctly.
The environment is production.
All push notification are handled by iOS not your app, iOS will deliver the push notification to your app after the user clicked/swiped the view option.
Did you set the correct type of notification, UIRemoteNotificationTypeAlert for alerts(banners) when you register for notifications?
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)];
More you can't set the 'Alert Style', the user can do this in settings app. You can't force the way Notifications are presented.

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.