5

I know there is a possibility to check whether or not the user has disabled the push settings, as described in objective c - Detect when user change the app's notifications settings.

According to the article above, the push notification is sent even if the user has disabled push notifications for the application. As I understand it I should always register for push notifications in applicationDidFinishLaunching:.

Most example looks like this, i.e. the user settings are ignored.

- (void)applicationDidFinishLaunching:(UIApplication *)app {
    // other setup tasks here....

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

}

If the application should take these settings into consideration, how does a correct implementation look like?

The reason why I ask this question is because we have a lot of customers complaining that they are getting push notifications although they have disabled push notifications. This seems to apply to iOS 6.

Should I as a developer take care of the case when the user has disabled push notifications? I have read the documentation over and over again. In particular the documentation for application:didReceiveRemoteNotification:. It does not states if it is called when the user has disabled push notifications.

Community
  • 1
  • 1
Johan Karlsson
  • 1,136
  • 1
  • 14
  • 37
  • 1
    Can you be more precise about the nature of the iOS changes or answer inconsistency to which you allude? My understanding is that the app registers for notification (regardless of the user's settings, because by the time of the subsequent notification, the user may have changed their settings), the notification is generated at future date, the user either sees the notification and may act or not act upon on it, or the user doesn't the notification. I'm not sure what the question really is here. But, no, registration does not fail because the user currently has notifications off. – Rob Dec 03 '12 at 14:12
  • I also understand that no push notifications are shown by the iOS when it has been disabled. However there is no mentioning if the application gets notified when it has registered and the user has disabled push notification. Is it safe to always register even if the user has disabled push notifications? I have tried to clarify the question accordingly. – Johan Karlsson Dec 03 '12 at 14:28
  • I was looking at this article and got confused about the differences in different iOS versions: [objective c - Detect when user change the app's notifications settings](http://stackoverflow.com/questions/1535403/determine-on-iphone-if-user-has-enabled-push-notifications). According to the comments on one of the answers, a change has been made in iOS 5. – Johan Karlsson Dec 03 '12 at 14:37
  • I don't get the problem here. You are calling `registerForRemoteNotificationTypes` every time the application is launched and then the notification will be delivered but not shown and therefore processed if it is disabled for the moment. That's how push notifications work and that's why you don't rely on them completely for triggering any kind of updates. – A-Live Dec 03 '12 at 15:40
  • Could you please back up tour statement with a reference to the documentation? It is not clear whether or not the application gets a callback or not when the user has disabled push notification. I have read the documentation for `application:didReceiveRemoteNotification:` and cannot find any information about this. Like you point put, the push notification will not be shown by the operating system when the user has disabled push notifications. Do you get my point? – Johan Karlsson Dec 04 '12 at 07:14
  • I have tried to clarify my question... – Johan Karlsson Dec 04 '12 at 07:26

1 Answers1

3

make sure you implement these methods to know whether the device registered or not

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
        if ([application enabledRemoteNotificationTypes] < 4) {
         NSLog(@"Notifications are disabled for this application");
    return;
        }
      // The device is registered for notifications
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
    NSLog(@"FAILED TO REGISTER FOR PUSH NOTIFICATIONS");
    NSLog(@"%@", error.userInfo);
}

it is ok to register for push notifications everytime your app is launched. but you have to make sure you implement the methods above to know if the user has enabled or disabled notifications for the app.

Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52
  • This sounds like the answer that I was looking for. It would be even better if you explained the magic '4' in the if-statement. I will add this to my code. – Johan Karlsson Dec 04 '12 at 07:01
  • here's more info about UIApplication's enabledRemoteNotificationTypes http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006728-CH3-SW65 if the value >= 4, then its enabled. – Nitin Alabur Dec 04 '12 at 20:45
  • more explanation: since the enabledRemoteNotificationTypes return value is bitwise typedef enum, I am interested in UIRemoteNotificationTypeAlert being enabled. so I am checking for 4. If you are interested in other alerts, like badge and sound, then you can check for those separately – Nitin Alabur Dec 04 '12 at 21:24
  • BTW Have you found any documentation stating that you must implement this method? – Johan Karlsson Mar 06 '13 at 08:23
  • @JohanKarlsson its not a "must". Without implementing these methods you won't know if push notifications were enabled or disabled by the user – Nitin Alabur Jun 03 '14 at 15:26