Objective-C - Detect when user change the app's notifications settings
I need to always know which options the user choose on the push notification settings.
(The options are - alert, sound and badges)
So when my app launch I call:
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
and detect what the user chose.
But how can I detect if the user change the settings later during the app life time?
Is there some delegate method that get called when a change occur with this settings?
There is no delegate. You need to query the UIApplication
property enabledRemoteNotificationTypes
periodically, for example in applicationDidBecomeActive:
.
For details check these answers:
Determine on iPhone if user has enabled push notifications
View In Lock Screen and enabledRemoteNotificationTypes - iOS5
Edit:
If you need to reset the push notification setting and the permission alert, have a look at the Apple technical note TN2265. In section "Resetting the Push Notifications Permissions Alert on iOS" they explain how to reset the setting on iOS. However, many developers complain that the procedure doesn't work. Not sure if this link will work, you will need to have access to the Apple forum, but it is one of the threads about this exact issue.
I was myself wondering if maybe Apple has removed the permission dialog in iOS 5.1. Otherwise why would they require the application to show the alert? According to AppStore review guidelines until June 2016:
5.3 Apps that send Push Notifications without first obtaining user consent will be rejected
For example Path (application) asks the user to opt-in for push notification in the middle of the sing-up process, not when the application starts for the first time.
Not sure what should be the purpose of the prompt anyway as the application can't query the state of the notification setting. In particular, the application can check which notification types (using enabledRemoteNotificationTypes
) are enabled but NOT if push notifications for a particular application are enabled or disabled (the Notification Center ON/OFF switch at the top). At least that's the behavior in iOS 5.1. Even if user disables notifications for that application, the application can still register for push notifications (using registerForRemoteNotificationTypes
) and WILL receive an APNS token.
Check it when your app becomes active rather than just at launch.