Reputation: 429
I am using Amazon SNS for mobile push notification and the AWS SDK in my swift based iOS Application. Everything works great, but I notice some weird behavior when I disable notification from the iOS Settings and then I turn off notifications under my application entry in Settings. If I turn notifications off, the enabled flag on the AWS SNS console is still set to true.
In some cases, the enabled flag will flip correctly to false. In those scenarios, when I try to re-enable notifications in the iOS Settings, the enabled flag will never flip back to true. Any idea why this is happening? Is there anyway to get this to set appropriately in real-time?
Thanks in advance.
Upvotes: 2
Views: 4760
Reputation: 204
There is no interaction between Amazon SNS and devices, SNS interacts only with platform providers (GCM, APNS, Baidu, WMS, etc.)
An endpoint can become disabled in Amazon SNS for several reasons:
The device token has changed you have not updated the endpoint with the new token. In this scenario, the push notification will fail to this device because the current endpoint token is invalid. Based on the APNS feedback, the endpoint will be set to DISABLED. Device token can change if:
The advice here is to verify the token change by your application on startup by matching the freshly obtained token with the one saved in NSUserDefaults store and if different, update it locally after updating the SNS endpoint.
This is likely why when you re-enable notification in device settings, "the enabled flag will never flip back to true".
The device owner has removed the application and while the app is not installed, an SNS notification is sent to the device. At this point, APNS provides feedback of an invalid token and the endpoint is DISABLED by SNS. This may take up to 24 hours due to async nature of APNS callbacks for disabled endpoints.
SNS notification is sent to an endpoint with a token that was not generated for the application or environment. For example, the endpoint was generated manually and is a random combination of valid hex chars of 64 length.
If SNS notification with a valid token destined for a SANDBOX (APNS_SANBOX) environment of the application was inadvertently sent to PRODUCTION (APNS) environment. In this scenario, SNS accepts the token but fails on the first push notification and the endpoint will be DISABLED based on APNS feedback.
The blog post shared by Rohan is a great resource for mobile token Management.
Upvotes: 4
Reputation: 3595
Amazon SNS disables the endpoint in response to feedback from APNS that indicates the push token is invalid. SNS is not aware of what action is performed on the device to make the token invalid; it merely sets the status based on APNS feedback messages.
You should review the Mobile Token Management blog post for specifics and best practices to handle disabled endpoints.
Upvotes: 4