

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 管理 Amazon SNS 移动推送通知的最佳实践
<a name="mobile-push-notifications-best-practices"></a>

本部分介绍可帮助您提升客户参与度的最佳实践。

## 终端节点管理
<a name="channels-sms-best-practices-endpoint-management"></a>

如果由于用户在设备上进行操作（例如，在设备上重新安装应用程序）导致设备令牌发生变化，或者[证书更新](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_certificate-based_connection_to_apns)影响了在特定 iOS 版本上运行的设备，则可能导致传送过程出现问题。Apple 推荐的最佳做法是在 APNs 每次启动应用程序时进行[注册](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/HandlingRemoteNotifications.html#:~:text=Registering%20to%20Receive%20Remote%20Notifications)。

由于在用户每次打开应用时设备令牌不会发生变化，因此可以使用幂等 [https://docs.aws.amazon.com/sns/latest/api/API_CreatePlatformEndpoint.html](https://docs.aws.amazon.com/sns/latest/api/API_CreatePlatformEndpoint.html) API。但是，如果令牌本身无效，或者端点有效但已禁用（例如，生产环境和沙盒环境不匹配），则上述方法可能会为同一设备引入重复项。

可以使用设备令牌管理机制，例如[伪代码](mobile-platform-endpoint.md#mobile-platform-endpoint-pseudo-code)中的一种此类机制。

有关管理和维护 FCM v1 设备令牌的信息，请参阅 [Amazon SNS 管理 Firebase Cloud Messaging 端点](sns-fcm-endpoint-management.md)。

## 传送状态日志记录
<a name="channels-sms-best-practices-delivery-logging"></a>

要监控推送通知传送状态，我们建议您为 Amazon SNS 平台应用程序启用传送状态日志记录。这有助于您排查传送失败问题，因为日志包含从推送平台服务返回的提供商[响应代码](sns-msg-status.md#platform-returncodes)。有关启用传送状态日志记录的详细信息，请参阅[如何访问 Amazon SNS 主题的推送通知传送日志记录？](https://aws.amazon.com/premiumsupport/knowledge-center/troubleshoot-failed-sns-deliveries/)

## 事件通知
<a name="channels-sms-best-practices-event-notifications"></a>

要以事件驱动的方式管理终端节点，您可以利用[事件通知](application-event-notifications.md#application-event-notifications-sdk)功能。这样，已配置的 Amazon SNS 主题就可以针对终端节点创建、删除、更新和传送失败等平台应用程序事件，向订阅者（例如 Lambda 函数）发送事件。