Azure 通知中樞提供一個易於使用且可擴展的推送引擎。使用通知中樞可將通知發送到任何平台(iOS、Android、Windows),並且可從任何後端(雲端或內部部署)發送通知。 欲了解更多資訊,請參閱 《什麼是 Azure 通知中心?》
在本快速入門中,您會使用通知中樞中的平臺通知系統 (PNS) 設定,在多個平台上設定推播通知。 快速入門說明使用 Azure 入口網站時所要採取的步驟。
Google Firebase 雲端通訊 包含使用 Azure CLI 的指示。
如果您尚未建立通知中樞,請立即建立一個。 如需詳細資訊,請參閱在 Azure 入口網站 中建立 Azure 通知中樞或使用 Azure CLI 建立 Azure 通知中樞。
Apple Push Notification Service
若要設定 Apple Push Notification Service (APNS):
在 Azure 入口網站的 [通知中樞] 頁面上,從左側功能表中選取 [Apple (APNS)]。
針對 [驗證模式],選取 [憑證] 或 [權杖]。
如果您選取 [憑證]:
- 選取檔案圖示,然後選取您要上傳的 [.p12] 檔案。
- 輸入密碼。
- 選取 [沙箱] 模式。 或者,若要傳送推播通知給從市集購買應用程式的使用者,請選取 [生產] 模式。
如果您選取 代幣:
- 輸入「金鑰識別碼」、「套件識別碼」、「小組識別碼」 和「權杖」的值。
- 選取 [沙箱] 模式。 或者,若要傳送推播通知給從市集購買應用程式的使用者,請選取 [生產] 模式。
如需詳細資訊,請參閱 使用 Azure 通知中樞將推播通知傳送至 iOS 應用程式。
Google Firebase 雲端通訊 V1 (FCMv1)
若要設定Google FCMv1的推播通知:
- 在 [Azure 入口網站] 的 [通知中樞] 頁面上,從左側功能表中選取 [Google(FCMv1)]。
- 更新從 Firebase 控制台取自的服務帳戶 JSON 檔案中的私鑰、專案識別碼和客戶端電子郵件值。
- 選取儲存。
當您完成這些步驟時,警示表示通知中樞已成功更新。 [儲存] 按鈕已停用。
Google Firebase 雲端通訊 (FCM)
備註
Firebase 雲端傳訊 (FCM) 已被取代,不再支援。
若要設定Google FCM的推播通知:
在 [Azure 入口網站] 的 [通知中樞] 頁面上,從左側功能表中選取 Google (GCM/FCM)。
貼上 您稍早儲存之 Google FCM 專案的 API 金鑰 。
選取儲存。
當您完成這些步驟時,警示表示通知中樞已成功更新。 [儲存] 按鈕已停用。
您需要 Google Firebase 雲端通訊 (FCM) 專案的 API 金鑰 。
備妥環境以使用 Azure CLI
- 本文需要 Azure CLI 2.0.67 版或更新版本。 如果您使用 Azure Cloud Shell,則已安裝最新版本。
設定Google FCM的推播通知
使用 az notification-hub credential gcm update 命令,將 Google API 金鑰新增至通知中樞。
az notification-hub credential gcm update --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --google-api-key myKey
Android 應用程式需要 連接字串 才能與通知中樞連線。
使用 az notification-hub authorization-rule list 命令來列出可用的存取原則。 使用 az notification-hub authorization-rule list-keys 命令以取得存取政策的連接字串。 指定在 primaryConnectionString 或 secondaryConnectionString 於 --query 參數以直接取得主要連接字串。
#list access policies for a notification hub
az notification-hub authorization-rule list --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --output table
#list keys and connection strings for a notification hub access policy
az notification-hub authorization-rule list-keys --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --name myAccessPolicyName --output json
#get the primaryConnectionString for an access policy
az notification-hub authorization-rule list-keys --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --name myAccessPolicyName --query primaryConnectionString
使用 az notification-hub test-send 命令來測試將訊息傳送至 Android 應用程式。
#test with message body
az notification-hub test-send --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --notification-format gcm --message "my message body"
#test with JSON string
az notification-hub test-send --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --notification-format gcm --payload "{\"data\":{\"message\":\"my JSON string\"}}"
您可以使用 az notification-hub credential 命令來取得其他平臺的 Azure CLI 參考。
如需將通知傳送至 Android 應用程式的詳細資訊,請參閱 使用 Firebase 將推播通知傳送至 Android 裝置。
Windows 推播通知服務
若要設定 Windows 推播通知服務 (WNS):
在 Azure 入口網站的 [通知中心] 頁面上,從左側功能表中選取 Windows (WNS)。
輸入 [套件 SID] 和 [安全性金鑰] 的值。
選取儲存。
如需詳細資訊,請參閱 使用 Azure 通知中樞將通知傳送至 UWP 應用程式。
當您完成這些步驟時,警示會指出通知中樞已成功更新。 [儲存] 按鈕已停用。
如需詳細資訊,請參閱 透過百度開始使用通知中樞。
下一步
在本快速入門中,您已瞭解如何在 Azure 入口網站 中設定通知中樞的平臺通知系統設定。
若要深入瞭解如何將通知推播至各種平臺,請參閱下列教學課程: