Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-enable an Amazon SNS endpoint with the iOS SDK?

I'm using Amazon SNS to send push notifications to my iOS app.

For whatever reason, my endpoints occasionally seem to get set to "false" - even though I know that they are valid endpoints (because re-enabling them then delivers new push notifications to the device). There's a similar Stack Overflow question here - but no technical answer as to how to resolve the issue.

So: I need to figure out how to set the endpoint as enabled.

There's only sparse Amazon documentation for how to do this, so what I do know is that I need to use the "enabled" key/value in the attributes dictionary.

My snippet of code looks like this:

AmazonSNSClient *sns = [AmazonClientManager sns];

SNSCreatePlatformEndpointRequest *endpointPutRequest = [SNSCreatePlatformEndpointRequest new];
endpointPutRequest.platformApplicationArn = kBXTAWSAppARN;
endpointPutRequest.token = deviceToken;
[endpointPutRequest setAttributesValue:@"True" forKey:@"Enabled"];

SNSCreatePlatformEndpointResponse *endpointResponse = [sns createPlatformEndpoint:endpointPutRequest];

This works perfectly, except for a single line of code, which sets the attributesValue "Enabled" to "true". I've tried all of these combinations:

[endpointPutRequest setAttributesValue:@"true" forKey:@"Enabled"];
[endpointPutRequest setAttributesValue:@"true" forKey:@"enabled"];
[endpointPutRequest setAttributesValue:@"True" forKey:@"Enabled"];

...yet none of them work. What is the proper way to write this line of code? Should I be using a BOOL somehow? An integer?

like image 402
bryanjclark Avatar asked May 16 '14 16:05

bryanjclark


People also ask

Why is SNS endpoint disabled?

When a mobile platform (such as APNs or FCM) informs Amazon SNS that the device token used in the publish request was invalid, Amazon SNS disables the platform endpoint associated with that device token. Amazon SNS will then reject subsequent publishes to that device token.

How do I enable push notifications on IOS?

Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered — immediately or in the scheduled notification summary.

How do I enable push notifications on Amazon?

Open the Amazon Pinpoint console at https://console.aws.amazon.com/pinpoint/ . On the All projects page, choose the project that you want to update push notification settings for. In the navigation pane, under Settings, choose Push notifications. Next to Push notifications, choose Edit.

Is Amazon SNS supported in the AWS Management Console?

The AWS Management Console now provides full support for the Amazon Simple Notification Service. You can create and subscribe to topics, and you can publish notifications to topics.


3 Answers

There are some conditions which I have found so far in which endPoint attributes gets false even though endpoints and tokens are correct

  1. If you have created the amazon sns app with Production APNS certificate but you try to register your device with SANDBOX APNS i.e. Development APNS then it will get false

  2. When user turns off notifications in Phone Settings then apple APNS disables the flag which affects in amazon sns too. whenever user enables the notification again you have resend the token to amazon to setattribute true i.e. need to handle on client side

  3. When user removes/unistalls the app

like image 138
user1169079 Avatar answered Nov 02 '22 23:11

user1169079


According to the following when re-enabling the endpoint "...you do need to update the token before you can set enabled on an endpoint".

This can be accomplished with two separate calls: CreatePlatformEndpoint to create/update the token followed by SetEndpointAttributes to set "Enabled" to "true"

This was tested by manually disabling the endpoint via the SNS console and then re-registering the device and using the two calls above.

like image 28
filitchp Avatar answered Nov 02 '22 23:11

filitchp


I'm using the PHP SDK but encountered the same error. The only solution I found was to first call the 'createPlatformEndpoint' method without the Enabled attribute and afterwards call the 'setEndpointAttributes' method to set the Enabled flag of the endpoint to true.

like image 22
Rob Avatar answered Nov 03 '22 00:11

Rob