I added push notification handling codes to my xamarin forms UWP application.
Codes:
async Task InitRemoteNotificationAsync()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
if (channel != null)
{
channel.PushNotificationReceived += OnPushNotificationReceived;
Debug.WriteLine($"Received token:{channel.Uri}");
}
}
private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
{
if (args.ToastNotification.Content.InnerText != null)
{
var msg = args.ToastNotification.Content.InnerText;
Xamarin.Forms.MessagingCenter.Send<object, string>(this, MyProject.App.NotificationReceivedKey, msg);
}
}
I have added null checks in my codes. When I try to push a test notification from the http://pushtestserver.azurewebsites.net/wns/ getting the following exception.
Exception caught sending update: System.NullReferenceException: Object reference not set to an instance of an object. at WebRole1.WNS.WebForm1.PostToWns(String secret, String sid, String uri, String xml, String notificationType, String contentType) at WebRole1.WNS.WebForm1.btnDiyPush_Click(Object sender, EventArgs e)
Screenshot: