I upgraded a windows phone 8 app to 8.1 silverlight. But while working with geofencing I wanted to show a toast. So I wrote this code
public sealed class Task : IBackgroundTask
{
static string TaskName = "GeofenceTask";
public void Run(IBackgroundTaskInstance taskInstance)
{
// Get the information of the geofence(s) that have been hit
var reports = GeofenceMonitor.Current.ReadReports();
var report = reports.FirstOrDefault(r => (r.Geofence.Id == "sample") && (r.NewState == GeofenceState.Entered));
if (report == null) return;
// Create a toast notification to show a geofence has been hit
var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var txtNodes = toastXmlContent.GetElementsByTagName("text");
txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Geofence triggered toast!"));
txtNodes[1].AppendChild(toastXmlContent.CreateTextNode(report.Geofence.Id));
var toast = new ToastNotification(toastXmlContent);
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toast);
}
}
But during certification it says
This API is not supported for this application type - Api=Windows.UI.Notifications.ToastNotification. Module=. File=GeofenceTask.winmd.
After which I did some research and found this answer which says
you have to select WNS if you want to use Windows.UI.Notifications otherwise you have the use ShellToast
So I was using MPN because Azure mobile service does not support WNS for WP8.1 silverlight apps.
Notification Hubs Windows Phone SDK does not support using WNS with Windows Phone 8.1 Silverlight apps.
So I thought I should use ShellToast in that case. But now I reached the real dead end. ShellToast is not supported in Windows runtime component projects. I dont have the right reference needed. i.e., Microsoft.Phone.Shell. If I add
Using Microsoft.Phone.Shell;
'Phone' shows with red underline. What should I do?
Update:
I tried to add the Microsoft.phone.dll from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0
but I got an error where the ToastShell was defined which says:
An exception of type 'System.InvalidProgramException' occurred in GeofenceTask.winmd but was not handled in user code
Additional information: Common Language Runtime detected an invalid program.