My app sends users push notifications. It includes a setting for the user to specify the time of day she would like to receive the notification.
When the app is first opened (and push notifications are accepted), I write a record to my server with the user's push token and the default time setting. Whenever the time setting is changed, I similarly update the setting.
Like a good APNS citizen, I also check nightly for expired tokens from users who have deleted the app or disabled push notifications. I remove these tokens from my database. Herein lie my problems.
If the user disabled notifications from settings, re-opens my app, and changes the 'time' setting, I go ahead and write the setting to my server as per usual. My app doesn't know that the user previously turned off notifications. The user won't receive the notifications since APNS will reject them, but I will still be sending them to the push server incorrectly. Is there some way for the app to know that push was disabled and therefore refrain from sending the setting to my server (or even better, allowing me to hide the settings UI and instead display a message telling the user that push is disabled)? Or how else can I handle this?
On day one, the user installs my app and my server receives the token. On day two, she disables push from the settings - later that night I get notice of the expired token and remove it from my database. On day three, she re-enables push from the settings. I receive no notice of this (since my app is not even opened), and the user will not receive the notifications she is expecting. Is there anything I can do about this?
The app can check the current status of push notifications :
You can query the currently enabled notification types using the enabledRemoteNotificationTypes property of UIApplication or the enabledRemoteNotificationTypes property of NSApplication.
I suggest that when you get a device token from Apple's Feedback Service, you don't delete that token from your DB. Instead, mark it with an inactive status.
This way you can allow your users to update the time of delivery settings even when push notifications are disabled for the app.
When the app is launched, you should check if push notifications are enabled, and if they are, call the server to make sure the status of the device token is active.
Now, if the user disabled push notifications and enabled them later (after your server already got the device token from the feedback service and de-activated the token), the next time your app is launched you'll notify your server to activate the device token.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With