

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在應用程式中接收推送通知
<a name="mobile-push"></a>

下列主題說明如何修改 Swift、Android、React Native 或 Flutter 應用程式，以便接收推送通知。

**Topics**
+ [設定快速推播通知](#apns-setup)
+ [設定 Android 推送通知](#mobile-push-android)
+ [設定 Flutter 推播通知](#mobile-push-flutter)
+ [設定 React Native 推播通知](#mobile-push-react-native)
+ [在 AWS 最終使用者傳訊推送中建立應用程式](#mobile-push-create-project)
+ [處理推送通知](#integrate-push-services)

## 設定快速推播通知
<a name="apns-setup"></a>

iOS 應用程式的推播通知，是使用 Apple 推播通知服務 (APN) 傳送。在您可以傳送推送通知至 iOS 裝置之前，您必須在 Apple 開發人員入口網站上建立一個應用程式 ID，並且必須建立必要的憑證。您可以在 AWS Amplify 文件的設定[推送通知服務](https://docs.amplify.aws/lib/push-notifications/getting-started/q/platform/ios/)中找到有關完成這些步驟的詳細資訊。

### 使用 APNS 字符
<a name="apns-setup-best-practices"></a>

根據最佳實務，您應該開發應用程式，以便在重新安裝應用程式時重新產生客戶的裝置字符。

如果收件人將其裝置升級到新的 iOS 主要版本 (例如，從 iOS 12 升級到 iOS 13)，並在稍後重新安裝您的應用程式，則應用程式會產生新的字符。如果您的應用程式未重新整理字符，則會使用較舊的字符來傳送通知。因此，Apple 推播通知服務 (APNS) 會拒絕通知，因為字符現在無效。嘗試傳送通知時，您會收到來自 APNS 的訊息失敗通知。

## 設定 Android 推送通知
<a name="mobile-push-android"></a>

Android 應用程式的推播通知是使用 Firebase Cloud Messaging (FCM) 傳送 (以前使用 Google Cloud Messaging (GCM))。您必須先取得 FCM 憑證，才能將推播通知傳送到 Android 裝置。接著您可以使用那些登入資料來建立 Android 專案，並啟動可接收推送通知的範例應用程式。您可以在 AWS Amplify 文件的[推送通知](https://docs.amplify.aws/lib/push-notifications/getting-started/q/platform/android/)區段中找到有關完成這些步驟的詳細資訊。

## 設定 Flutter 推播通知
<a name="mobile-push-flutter"></a>

Flutter 應用程式的推播通知在 Android 裝置上是使用 Firebase Cloud Messaging (FCM) 傳送，在 iOS 裝置上是使用 APN 傳送。您可以在 [AWS Amplify Flutter 文件](https://docs.amplify.aws/gen1/flutter/build-a-backend/push-notifications/set-up-push-notifications/)的推播通知區段中，找到完成相關步驟的詳細資訊。

## 設定 React Native 推播通知
<a name="mobile-push-react-native"></a>

React Native 應用程式的推播通知在 Android 裝置上是使用 Firebase Cloud Messaging (FCM) 傳送，在 iOS 裝置上是使用 APN 傳送。您可以在 [AWS Amplify JavaScript](https://docs.amplify.aws/gen1/react-native/build-a-backend/push-notifications/set-up-push-notifications/) 文件的推播通知區段中，找到完成相關步驟的詳細資訊。

## 在 AWS 最終使用者傳訊推送中建立應用程式
<a name="mobile-push-create-project"></a>

若要在 AWS 最終使用者傳訊推送中開始傳送推送通知，您必須建立應用程式。接著，您必須提供適當的登入資料，以啟用您想要使用的推送通知管道。

您可以使用 AWS 最終使用者訊息推送主控台建立新的應用程式和設定推送通知管道。如需詳細資訊，請參閱[建立應用程式並啟用推送頻道](procedure-enable-push.md)。

您也可以使用 [API](https://docs.aws.amazon.com/pinpoint/latest/apireference/)、 [AWS SDK](https://aws.amazon.com/developer/tools/#sdk) 或 [AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/reference/pinpoint/)() 來建立和設定應用程式AWS CLI。若要建立應用程式，請使用 `Apps` 資源。若要設定推送通知管道，請使用下列資源：
+ [APN 管道](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-channels-apns.html)使用 Apple 推播通知服務向 iOS 裝置的使用者傳送訊息。
+ [ADM 管道](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-channels-adm.html)，以傳送訊息給 Amazon Kindle Fire 裝置的使用者。
+ [百度管道](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-channels-baidu.html)，以傳送訊息給百度使用者。
+ [GCM 管道](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-channels-gcm.html)使用 Firebase Cloud Messaging (FCM) (以前使用 Google Cloud Messaging (GCM))，向 Android 裝置傳送訊息。

## 處理推送通知
<a name="integrate-push-services"></a>

在您取得傳送推播通知所需的登入資料後，您可以更新您的應用程式，以便他們能夠接收推播通知。如需詳細資訊，請參閱[推播通知 - 在文件中開始](https://docs.amplify.aws/lib/push-notifications/getting-started/)。 AWS Amplify 