【问题标题】:How to re-enable an Amazon SNS endpoint with the iOS SDK?如何使用 iOS 开发工具包重新启用 Amazon SNS 终端节点?
【发布时间】:2015-04-22 07:08:14
【问题描述】:

我正在使用 Amazon SNS 向我的 iOS 应用发送推送通知。

无论出于何种原因,我的端点有时似乎被设置为“假”——即使我知道它们是有效的端点(因为重新启用它们然后会向设备发送新的推送通知)。 There's a similar Stack Overflow question here - but no technical answer as to how to resolve the issue.

所以:我需要弄清楚如何将端点设置为enabled

only sparse Amazon documentation 说明如何做到这一点,所以我知道我需要使用属性字典中的“启用”键/值。

我的 sn-p 代码如下所示:

AmazonSNSClient *sns = [AmazonClientManager sns];

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

SNSCreatePlatformEndpointResponse *endpointResponse = [sns createPlatformEndpoint:endpointPutRequest];

这很好用,除了一行代码,它将属性值“启用”设置为“真”。我已经尝试了所有这些组合:

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

...但它们都不起作用。编写这行代码的正确方法是什么?我应该以某种方式使用 BOOL 吗?整数?

【问题讨论】:

    标签: ios amazon-web-services push-notification amazon-sns


    【解决方案1】:

    到目前为止,我发现在某些情况下,即使端点和令牌正确,endPoint 属性也会变为错误

    1. 如果您已经使用生产 APNS 证书创建了 amazon sns 应用程序,但您尝试使用 SANDBOX APNS (即开发 APNS)注册您的设备,那么它将得到错误

    2. 当用户在电话设置中关闭通知时,苹果 APNS 也会禁用影响亚马逊 sns 的标志。每当用户再次启用通知时,您都会将令牌重新发送到亚马逊以设置属性为 true,即需要在客户端处理

    3. 当用户删除/卸载应用时

    【讨论】:

      【解决方案2】:

      根据following 重新启用端点时“...您确实需要更新令牌才能在端点上设置启用”。

      这可以通过两个单独的调用来完成:CreatePlatformEndpoint 创建/更新令牌,然后 SetEndpointAttributes 将“Enabled”设置为“true

      这是通过通过 SNS 控制台手动禁用端点,然后重新注册设备并使用上面的两个调用来测试的。

      【讨论】:

      • 感谢您的链接。尽管亚马逊说你需要“更新”令牌,但这只有在苹果提供新令牌时才有意义。大多数从苹果重新安装的同一个应用程序都给了我相同的令牌,这让我根本无法使用该设备进行通知。
      【解决方案3】:

      我正在使用 PHP SDK,但遇到了同样的错误。我找到的唯一解决方案是首先调用不带 Enabled 属性的“createPlatformEndpoint”方法,然后调用“setEndpointAttributes”方法将端点的 Enabled 标志设置为 true。

      【讨论】:

        猜你喜欢
        • 2023-03-26
        • 2020-01-20
        • 2016-04-24
        • 2021-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 2018-12-17
        相关资源
        最近更新 更多