6

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?

Community
  • 1
  • 1
bryanjclark
  • 6,247
  • 2
  • 35
  • 68

3 Answers3

5

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

user1169079
  • 3,053
  • 5
  • 42
  • 71
3

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.

filitchp
  • 616
  • 9
  • 8
  • Thanks for the link. Even though Amazon says you need to "update" token, that only ever makes sense if Apple provides a new one. Most of the reinstalls of the same app from apple gives me the same token, which leaves me unable to use that device for notifications at all. – Priyeshj Sep 01 '15 at 22:11
1

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.

Rob
  • 136
  • 1
  • 8