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

I use Amazon SNS to send push notifications to my iOS app.

For some reason, my endpoints sometimes seem to be set to false β€” although I know that they are valid endpoints (since re-enabling them then provides new push notifications for the device). There is a similar question about the stack overflow, but there is no technical answer as to how to solve the problem.

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

There is only sparse Amazon documentation on how to do this, so I know that I need to use the "enabled" / value key in the attribute dictionary.

My code snippet is as follows:

 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 fine except for one line of code that sets the Value "Enabled" attributes to "true". I tried all these combinations:

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

... but none of them work. What is the correct way to write this line of code? Should I use BOOL in some way? Integer?

+6
source share
3 answers

There are some conditions that I have found so far in which the endPoint attributes become false even if the endpoints and tokens are correct.

  • If you created an amazon sns application with a Production APNS certificate, but you are trying to register your device using SANDBOX APNS ie Development APNS, then it will receive false

  • When a user turns off notifications in the phone’s settings, Apple APNS turns off the flag, which affects amazon sns. whenever the user enters the notification again, you resend the token to amazon to set the true attribute, i.e. need to be processed on the client side.

  • When a user uninstalls / unistalls application

+5
source

According to below, when you turn on the endpoint again, "... you need to update the token before you can install it on the endpoint."

This can be done with two separate calls: CreatePlatformEndpoint to create / update the token, and then SetEndpointAttributes to set Enabled to " true "

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

+3
source

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

+1
source

Source: https://habr.com/ru/post/969392/


All Articles