简体   繁体   中英

How does Apple handle push tokens if you disable notifications after agreeing to them prior?

I am working with Leanplum and having trouble finding documentation around apples push tokens. The main question is if a user originally accepts notifications when the app is installed and a push token is generated but then disables notifications later on, does the phone itself restrict the notification or is it done on apples push servers? Mainly just trying to understand the process flow.

From what I've read the push token is the same unless the user resets their phone. So if leanplum has a push token for a user and we try to send a push notification after they went and disabled notifications what actually happens? Will leanplum remove the token or will that token be invalid? I understand this is vague, I'm just trying to learn more about what's going on under the hood with apples push process. Thanks for any help!

Summary

User permission has no effect on remote push notifications, and thus APNs registration (ie, token retrieval) is not affected. Therefore, your server-side push notification logic does not need to feel the impact of a user denying your application permission to present user-facing push notifications. You will continue to receive your remote push notifications even when the user does not consent to seeing them. The difference is that with a lack of permission, your push notifications are considered background remote notifications. Continue reading for further explanation.


Remote Push Notifications vs. User Notifications

APNs is a service that has the ability to remotely send a payload to a particular device, as identified by the app-device-specific token provided when registering for remote notifications. Push notifications seen by the user are not necessarily the same as a plain remote push notification. Remote notifications do not need explicit permission to be granted by the user. However, if the push notification is to be displayed to the user, only then is permission required.


User Permission & Server-Side of Push Notifications

To more directly answer your question: When your application launches you should register for remote notifications. That call will fetch an app-device token from APNs and then return it to you. If something prevented the registration from succeeding, another delegate method is called. Once you've registered for remote notifications, only then should you request user permission to display notifications to them. The user permission is only to display the notifications, so APNs will still work as intended without any change on the server-side. The only difference is how the device presents the information.

- (void)applicationDidFinishLaunching:(UIApplication *)app {
    // Configure the user interactions first.
    [self configureUserInteractions];

    // Register for remote notifications.
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

// Handle remote notification registration.
- (void)application:(UIApplication *)app
        didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    // Forward the token to your provider, using a custom method.
    // Setup user notifications.
    [self enableRemoteNotificationFeatures];
    [self forwardTokenToServer:devTokenBytes];
}

- (void)application:(UIApplication *)app
        didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    // The token is not currently available.
    NSLog(@"Remote notification support is unavailable due to error: %@", err);
    [self disableRemoteNotificationFeatures];
}

References:

Local and Remote Notification Programming Guide – Configuring Remote Notification Support

Experience from using solely remote notifications (ie, background) and user notifications.

Leanplum SDK simply uploads the push token to the Leanplum dashboard (server). Leanplum will use that token to talk to APNS (Apple Push Notification Service) and APNS talks to the device to show a push. Leanplum will remove the token if it is expired or invalidated.

User's device is talking to APNS constantly. So when the user disables notification on their phone, it simply ignores the pushes from Leanplum. It does not remove the push token immediately. Take it with grain of salt but I'm pretty sure the token does get expired at some point.

One case that we know when the token get invalidated is when user uninstalls the app. That's how Leanplum tracks uninstalls. It's not completely accurate as same user can reinstall the app and track as uninstall but it's the closest thing we got.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM