Getting “EndpointDisabled” from Amazon SNS

前端 未结 9 948
深忆病人
深忆病人 2020-12-23 11:34

I\'m using Amazon SNS. Notifications work well, but sometimes I get this error:

{
    \"message\": \"Endpoint is disabled\",
    \"code\": \"EndpointDisabled         


        
相关标签:
9条回答
  • 2020-12-23 12:01

    I had the same issue. This is what I did:

    1. export the FULL CERTIFICATE from Keychain Access to a .p12 file
    2. export the PRIVATE KEY from Keychange Access to a *private.p12 file

    3. use openssl with the downloaded .cer file (from iOS Developer MemberCenter) to create a public .pem certificate

    4. use openssl with the generated *private.p12 file to create a private .pem keyfile

    5. In AWS SNS create a new Application. Give it a name. Choose Apple Development.
    6. Choose the FULL CERTIFICATE from Keychain Access with a .p12 extension, and type in the passphrase you chose when exporting from Keychain Access Copy the content of the public CERTIFICATE .pem file, to the textarea labelled "Certificate", including the starting and ending lines:

      -----BEGIN CERTIFICATE-----
      -----END CERTIFICATE-----
      
    7. Copy only the part of the private key .pem file starting and ending with the following lines, to the textarea labelled "Private Key":

      -----BEGIN RSA PRIVATE KEY-----
      -----END RSA PRIVATE KEY-----
      

    I use Cordova with phonegap-plugin-push 1.4.4, but it my issue had nothing to do with phonecap. Apart from a bit of confusion about the above, what finally did the trick for me, was to open up my project in XCode, find the Target for my project, and then enable Push Notifications. This automatically adds the "Push Notifications" entitlement to the app ID.. The next time the app is installed on your device, push notification should work. At least it did for me.

    I hope this can save someone experiencing the same issue as me a 1/2 day of work! :)

    0 讨论(0)
  • 2020-12-23 12:04

    I have found 3 reasons so far:

    • Sometimes we mixed tokens from sandbox app.
    • User turn off notifications in phone settings.
    • User uninstalled the app.

    These are regarding Iphons/Ipads.

    0 讨论(0)
  • 2020-12-23 12:04

    I am using this. If the get endpoint response finds the NotFound error, it creates an endpoint (this should never happen, but hell, it's on AWS SNS documentation website). If that doesn't happen, it means you're getting the info for the endpoint. It can either be ok (tokens match and enabled is true), or the other way around (in which case you need to update it).

        - (void)getEndpointDetailsWithResponse:(void(^)(AWSSNSGetEndpointAttributesResponse *response, AWSTask *))handleResponse {
        NSString * deviceTokenForAWS = [self deviceTokenForAWS];
        AWSSNS *manager = [AWSSNS SNSForKey:@"EUWest1SNS"];
    
        AWSSNSGetEndpointAttributesInput *input = [AWSSNSGetEndpointAttributesInput new];
        input.endpointArn = self.endpointArn;
        AWSTask *getEndpointAttributesTask = [manager getEndpointAttributes:input];
        [getEndpointAttributesTask continueWithBlock:^id(AWSTask *task) {
            NSLog(@"%@ Error: %@", task.result, task.error);
    
    
            AWSSNSGetEndpointAttributesResponse *result = task.result;
            NSError *error = task.error;
    
            if (error.code == AWSSNSErrorNotFound) {
                [self createEndpointWithResponse:^(AWSSNSCreateEndpointResponse *createResponse) {
    
    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (handleResponse != nil) {
                            handleResponse(result, task);
                        }
                    });
                }];
            } else {
    
                NSLog(@"response for get endpoint attributes : %@", result);
    
                NSString *token = [result.attributes valueForKey:@"Token"];
                NSString *enabled = [result.attributes valueForKey:@"Enabled"];
                NSLog(@"token : %@, enabled : %@", token, enabled);
                BOOL wasSuccessful = [token isEqualToString:deviceTokenForAWS] && ([enabled localizedCaseInsensitiveCompare:@"true"] == NSOrderedSame);
    
                if (!wasSuccessful) {
                    NSLog(@"device token does not match the AWS token OR it is disabled!");
                    NSLog(@"Need to update the endpoint");
    
                    AWSSNSSetEndpointAttributesInput *seai = [AWSSNSSetEndpointAttributesInput new];
                    seai.endpointArn = self.endpointArn;
    
                NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:deviceTokenForAWS, @"Token", @"true", @"Enabled", nil];
                seai.attributes = attributes;
    
                    AWSTask *setEndpointAttributesTask = [manager setEndpointAttributes:seai];
                    [setEndpointAttributesTask continueWithBlock:^id(AWSTask *task) {
                        NSLog(@"response : %@, error: %@", task.result, task.error);
    
                        dispatch_async(dispatch_get_main_queue(), ^{
                            if (handleResponse != nil) {
                                handleResponse(result, task);
                            }
                        });
                        return nil;
                    }];
    
                } else {
                    NSLog(@"all is good with the endpoint");
    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (handleResponse != nil) {
                            handleResponse(result, task);
                        }
                    });
                }
            }
            return nil;
        }];
    }
    

    This is the exact replica of the AWS SNS token management documentation found here: https://mobile.awsblog.com/post/Tx223MJB0XKV9RU/Mobile-token-management-with-Amazon-SNS

    I can attach the rest of my implementation if needed, but this part is the most important one.

    0 讨论(0)
提交回复
热议问题