Amazon SNS - 如何知道该应用程序已被卸载?

Posted

技术标签:

【中文标题】Amazon SNS - 如何知道该应用程序已被卸载?【英文标题】:Amazon SNS - how to know that app has been uninstalled? 【发布时间】:2017-08-18 06:33:22 【问题描述】:

我是 Amazon SNS 的新手。

我的应用通过 Amazon SNS 使用 APNS 和 GCM。

所以每次用户安装我的应用时,我都会将它们注册到 GCM 或 APNS。

我想知道我的应用程序何时被卸载,以便我可以将它们从我的数据库中删除,并且不会向它们发送推送通知。

我在某处读到了有关 Apple 反馈服务和 GCM 返回 NOTREGISTERED 的信息,但解释不清楚,例如我在哪里可以获得这些服务和响应?

非常感谢任何帮助!

谢谢。

【问题讨论】:

【参考方案1】:

基于此blog,为了使用 SNS 将移动通知推送到应用程序,该应用程序的令牌需要首先使用 CreatePlatformEndpoint API 方法向 SNS 注册。

下面介绍的最佳实践可在各种启动条件下创建一个工作的、当前启用的端点。无论是否是第一次注册应用程序,无论此应用程序的 PlatformEndpoint 是否已经存在,以及 端点是否启用或禁用,或者是否具有正确的令牌等。该方法也是幂等的。连续多次运行它是安全的,并且不会创建重复的 PlatformEndpoints 或更改现有的 PlatformEndpoint,如果它已经是最新的并已启用。

retrieve the latest token from the mobile OS
if (endpoint arn not stored)
    # first time registration
    call CreatePlatformEndpoint
    store returned endpoint arn
endif

call GetEndpointAttributes on the endpoint arn 

if (getting attributes encountered NotFound exception)
    #endpoint was deleted 
    call CreatePlatformEndpoint
    store returned endpoint arn
else 
    if (token in endpoint does not match latest) or 
        (GetEndpointAttributes shows endpoint as disabled)
        call SetEndpointAttributes to set the 
                     latest token and enable the endpoint
    endif
endif

【讨论】:

如果端点因用户卸载应用程序而被禁用,我为什么要启用端点?

以上是关于Amazon SNS - 如何知道该应用程序已被卸载?的主要内容,如果未能解决你的问题,请参考以下文章

如何在一次 API 调用中通过 Amazon SNS 发送推送通知?

从我的 PHP 服务器发送 Amazon SNS

Amazon SQS/SNS 策略错误

在 iOS 设置中更改通知时,Amazon SNS 如何禁用/重新启用设备?

Amazon SNS 静默推送

使用 Amazon SNS 处理 GCM 规范 ID