Push Notifications are one-way forms of communication offered to mobile users that some operation (like an update, deletion, or addition) has happened.
To send a push notification to an Apple device, use the Apple Push Services. For an Android device, use Google’s Firebase Cloud Messaging Services. Fortunately, if you’re sending a push notification to an app on both platforms, Microsoft offers an easier way through Microsoft Azure Notification Hub.
Go to the Azure portal.
- Click “Create a resource”, “Web + Mobile” and select “Notification Hub.”
- In the new window, enter the notification hub name and create a new namespace.
- Select a location. We recommend a location closest to the user or closest to you (the developer).
- Choose an existing resource group or create a new resource group.
- Select your Microsoft subscription (for billing purposes).
- Choose a pricing tier based on your usage needs and click “Select” to close the pricing tab.
- Click “Create” to create the new notification hub. It may take few minutes to create and configure.
- Choose the “Google (GCM)” from the side menu. This section is used to configure and send Android-based push notifications using Birebase cloud messaging.
Create the Firebase Push Notifcation
- Open a new browser window and navigate to https://console.firebase.google.com/.
- Login or create a new account. After you have logged in, click “+ Add Project”.
- Enter the Project Name and Country/region. You can change the Project ID if required.
- Click “CREATE PROJECT.” It may take a few minutes to create the project.
- After the message “Your new project is ready”, click “CONTINUE” to navigate to the project page.
- In the new page, select “Add Firebase to your Android app” to create an Android-based Firebase app.
- In the next screen, enter the “Android package name” and enter an optional app nickname. Select “REGISTER APP.”
- In the next screen, click “Download google-services.json” and download the file.
- Open the downloaded file and copy the project number (a 12-digit code like 272477558565) into the project’s AppSettings.cs file for FirebaseSenderID.
Create push services for iOS:
- Select “Apple (APNS)” from the Azure portal side menu.
- Upload a certificate to send push notifications on iOS. Log in to https://developer.apple.com.
- Navigate to “Certificates, Identifiers and Profiles.”
- Select the Apple ID associated with the application.
- Ensure that the ID is configured to use Push Notifications. It should have the status as Configurable. Click “Edit” to configure push services.
- In the next screen, choose to create either a development or production SSL certificate and click “Create Certificate.”
- The next screen requires you to create a “certSigningRequest”. Create the file and upload it.
- On the Mac, open the “Keychain Access” application: press WinKey + Spacebar to open Spotlight. Type “keychain access” and press enter.
- Select Keychain Access -> Certificate Assistant -> Request a Certificate From a Certificate Authority.
- Enter the user email address, command name, and Certificate Authority (CA) Email address.
- Select “Saved to disk” and click “Continue”.
- In the popup dialog, save the certSigningRequest.
- Choose a location. If you’re choosing a default location, make sure to note the location for future purposes.
- Now navigate back to the apple developer website and upload the previously created certSigningRequest and select “Continue.”
- In the next screen, click “Download” button to download the .cer file. After downloading the file, select “Done” and close the browser.
- Double click to open the .cer file. It will by default open the Keychain Access application.
- Enter the administrator password to install the .cer file.
- Right-click on the certificate and choose “Export [Certificate Name].”Enter a name for the “.p12” file. Select the location of the file and click “Save.” Make sure the file format is “Personal Information Exchange (.p12)” before saving the file.
- Enter a password for the p12 file. Re-enter the password.
- Enter the administrator password for Keychain Access application to export the key and select “Allow.”
Now navigate back to the Azure portal.
- Select Folder Icon.
- Find the p12 file and click “Open.” Enter the same password used to create the file. Save.
- Open the Backend Mobile app service from the Azure portal and navigate to “Push” from the sidebar menu.
- Connect to the notification hub we created earlier.
- Choose the previously created notification hub.
- On the next screen, add the tag “UserGroup1” for push notifications to be delivered to the mobile devices. Save.
Looking for more Xamarin development tips? Check out our related blogs on mobile development