title | description | services | author | manager | ms.service | ms.topic | ms.date | ms.author | ms.reviewer | ms.lastreviewed | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|---|
Set up push notifications in Azure Notification Hubs | Microsoft Docs |
Learn how to set up Azure Notification Hubs in the Azure portal by using platform notification system (PNS) settings. |
notification-hubs |
sethmanheim |
femila |
notification-hubs |
quickstart |
06/30/2023 |
sethm |
thsomasu |
02/14/2019 |
mode-ui, devx-track-azurecli |
Azure Notification Hubs provides a push engine that's easy to use and that scales out. Use Notification Hubs to send notifications to any platform (iOS, Android, Windows, Baidu) and from any back end (cloud or on-premises). For more information, see What is Azure Notification Hubs?.
In this quickstart, you'll use the platform notification system (PNS) settings in Notification Hubs to set up push notifications on multiple platforms. The quickstart shows you the steps to take in the Azure portal. Google Firebase Cloud Messaging includes instructions for using the Azure CLI.
Note
For information about Firebase Cloud Messaging deprecation and migration steps, see Google Firebase Cloud Messaging migration.
If you haven't already created a notification hub, create one now. For more information, see Create an Azure notification hub in the Azure portal or Create an Azure notification hub using the Azure CLI.
To set up Apple Push Notification Service (APNS):
-
In the Azure portal, on the Notification Hub page, select Apple (APNS) from the left menu.
-
For Authentication Mode, select either Certificate or Token.
a. If you select Certificate:
-
Select the file icon, and then select the .p12 file you want to upload.
-
Enter a password.
-
Select Sandbox mode. Or, to send push notifications to users who purchased your app from the store, select Production mode.
b. If you select Token:
-
For more information, see Send push notifications to iOS apps using Azure Notification Hubs.
To set up push notifications for Google FCM:
-
In the Azure portal, on the Notification Hub page, select Google (GCM/FCM) from the left menu.
-
Paste the API Key for the Google FCM project that you saved earlier.
-
Select Save.
When you complete these steps, an alert indicates that the notification hub has been successfully updated. The Save button is disabled.
You will need the API Key for your Google Firebase Cloud Messaging (FCM) project.
[!INCLUDE azure-cli-prepare-your-environment.md]
- This article requires version 2.0.67 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
-
Use the az notification-hub credential gcm update command to add your Google API key to your notification hub.
az notification-hub credential gcm update --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --google-api-key myKey
-
The Android App needs a connection string to connect with the notification hub. Use the az notification-hub authorization-rule list command to list the available access policies. Use the az notification-hub authorization-rule list-keys command to get the access policy connection strings. Specify the primaryConnectionString or secondaryConnectionString in the
--query
parameter to get the primary connection string directly.#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
-
Use the az notification-hub test-send command to test sending messages to the Android App.
#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\"}}"
Get Azure CLI references for other platforms with the az notification-hub credential command.
For more information about sending notifications to an Android application, see Send push notifications to Android devices using Firebase.
To set up Windows Push Notification Service (WNS):
-
In the Azure portal, on the Notification Hub page, select Windows (WNS) from the left menu.
-
Enter values for Package SID and Security Key.
-
Select Save.
For information, see Send notifications to UWP apps by using Azure Notification Hubs.
Note
Microsoft Push Notification Service (MPNS) has been deprecated and is no longer supported.
To set up Microsoft Push Notification Service (MPNS) for Windows Phone:
-
In the Azure portal, on the Notification Hub page, select Windows Phone (MPNS) from the left menu.
-
Enable either unauthenticated or authenticated push notifications:
a. To enable unauthenticated push notifications, select Enable unauthenticated push > Save.
b. To enable authenticated push notifications:
- On the toolbar, select Upload Certificate.
- Select the file icon, and then select the certificate file.
- Enter the password for the certificate.
- Select OK.
- On the Windows Phone (MPNS) page, select Save.
For more information, see Push notifications to Windows Phone apps by using Notification Hubs.
To set up push notifications for Baidu:
-
In the Azure portal, on the Notification Hub page, select Baidu (Android China) from the left menu.
-
Enter the API Key that you obtained from the Baidu console in the Baidu cloud push project.
-
Enter the Secret Key that you obtained from the Baidu console in the Baidu cloud push project.
-
Select Save.
When you complete these steps, an alert indicates that the notification hub has been successfully updated. The Save button is disabled.
For more information, see Get started with Notification Hubs by using Baidu.
In this quickstart, you learned how to configure platform notification system settings for a notification hub in the Azure portal.
To learn more about how to push notifications to various platforms, see these tutorials:
- Send push notifications to iOS apps using Azure Notification Hubs
- Send notifications to Android devices by using Notification Hubs and Google FCM
- Send notifications to a UWP app running on a Windows device
- Send notifications to a Windows Phone 8 app by using MPNS
- Send notifications by using Notification Hubs and Baidu cloud push