Question

The first time I run my app, I get asked if I want to allow push notifications, so I select yes. Now, when I go to settings and turn off all notifications for my app, I still get a device token from - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;. Am I, as the dev, responsible to track if my app has any enabled? Or is this a bug?

Was it helpful?

Solution

The device token is generally stored on a server someplace. If the user suddenly decides they want push notifications and turns it back on, their device token has already been generated and stored on your server.

If the device token was not generated, then the user would have to make sure the app has been terminated and then re-launched in order for the device token to get generated.

You can determine if the user has turned off push notifications with the code below

UIRemoteNotificationType remoteNotificationType = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (remoteNotificationType == UIRemoteNotificationTypeNone) {
    ... Do not send push
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top