I'm developing an app in Windows Phone 8.1 (NOT silverlight) which uses WNS to receive raw push notification.
While I run my app through Visual Studio (over a physical device, not in the emulator), I always receive push notifications (with the app in foreground, in background, with the phone locked...) so I think my code to receive push is correct.
My issue is when I run my app whithout using Visual Studio. If I press the "app icon" on the device to init the app and keep it in foreground, I receive push notifications. But if I go to the phone menu, or lock the device (without killing the app), I don't receive push notifications, but the server says that WNS has been sent successfully. If I put the app again into foreground, I receive push notifications again...
So, summarizing: Init app through Visual Studio, I receive always the WNS notifications. Init app through device, only receive WNS with the app in foreground. The server always send the WNS successfully.
Here is my code to receive WNS:
public static void OnPushNotificationReceived(PushNotificationChannel channel, PushNotificationReceivedEventArgs e)
{
Debug.WriteLine("Received WNS notification");
string notificationContent = String.Empty;
switch (e.NotificationType)
{
case PushNotificationType.Badge:
Debug.WriteLine("Badge notifications not allowed");
return;
case PushNotificationType.Tile:
Debug.WriteLine("Tile notifications not allowed");
return;
case PushNotificationType.Toast:
Debug.WriteLine("Toast notifications not allowed");
return;
case PushNotificationType.Raw:
notificationContent = e.RawNotification.Content;
break;
}
processWnsNotification(notificationContent);
}
//Show local toast notification
private static void processWnsNotification(string notification)
{
ToastTemplateType toastTemplateXml = ToastTemplateType.ToastText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplateXml);
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("New message"));
ToastNotification toast = new ToastNotification(toastXml);
if(toastNotifier == null)
{
toastNotifier = ToastNotificationManager.CreateToastNotifier();
}
toastNotifier.Show(toast);
}
Anyone know what happens or what I'm doing wrong? I think it could be a configuration issue... but I've been digging into property and config files without success.
Thanks a lot!! Jorge.