Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

How to handle local notifications on Windows Phone

$
0
0

I'm having problems with navigation after user taps a local notification. My goal is to navigate user to specific view after he taps a notification. I already managed to make it work on both Android and iOS but I have problems with Windows Phone. As far I know on Windows Phone I can navigate between views using URIs. Class ScheduledToastNotification as a parameter gets a XML template of notification. I can set the 'launch' attribute of that XML with URI which should navigate me to specific view. I have two problems however:

  • In my Windows Phone project I have only MainPage.xaml view that I can navigate to. All other Views are contained in PCL and I don't know if it is possible to provide URI that points to View in PCL.

  • If 'launch' parameter of XML template is set and application is running (no matter if it is in foreground on background) I get an exception after notification is tapped.
    Click

Code that I use to set notification on Windows Phone:

public void Notify(INotification notification)
{
    var _notifier = ToastNotificationManager.CreateToastNotifier();
    var _toastNotificationSchema = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);

    var toastText = _toastNotificationSchema.GetElementsByTagName("text");

    ((XmlElement)toastText[0]).InnerText = notification.NotificationText;
    IXmlNode toastNode = _toastNotificationSchema.SelectSingleNode("/toast");
    ((XmlElement)toastNode).SetAttribute("launch", string.Format("/MainPage.xaml?notificationID={0}", notification.ID));

    var scheduledNotification = new ScheduledToastNotification(_toastNotificationSchema,
                                                               notification.FireDateTime,
                                                               TimeSpan.FromSeconds(60),
                                                               5)
                                {Id = notification.ID.ToString()};

    _notifier.AddToSchedule(scheduledNotification);
}

I think I could somehow hack solution of my issue if I would be able to set Query String and then access if after app is brought to foreground after user taps notification. I don't know if it is possible though.

Is there any way I can achieve navigation using local notifications on Windows Phone? I know that push notifications would solve all my problems but unfortunately I cannot use that.


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>