Xamarin.Forms Push notifications for Windows Phone with Azure


Example

On Windows Phone something like the code underneath needs to be implemented to start working with push notifications. This can be found in the App.xaml.cs file.

protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
 
    // TODO add connection string here
    var hub = new NotificationHub("XamarinNotifications", "<connection string with listen access>");
    var result = await hub.RegisterNativeAsync(channel.Uri);
 
    // Displays the registration ID so you know it was successful
    if (result.RegistrationId != null)
    {
        Settings.DeviceToken = result.RegistrationId;
    }
 
    // The rest of the default code is here
}

Also don't forget to enable the capabilities in the Package.appxmanifest file.

Package.appxmanifest

A sample push notification may look like this:

Toast on Windows Phone