问题
I'm facing a strange problem with my Windows Phone 8.1 App. The App will send a toast notification every time the user is near a Point of his interest using Geofence Quickstart: Setting up a geofence and BackgroundTask Quickstart: Listening for geofence events in the background
And this is the Background task (example)
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 == "id") && (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);
}
Now the problem is that if I run the App from VS all works fine and the Toast is triggered once entered the specific Area... if I install the App on the device using the Windows Phone Application Deployment the app works fine, and same using the Emulator. But once Uploaded to the store, I've downloaded the App and the Toast, Geofence or BackgroundTask doesn't work anymore (I guess the problem is one of those three but I don't know who is the culprit :s)... the toast notification just won't trigger..
I've also noticed that my App isn't listed in the "Notification+Action" settings, but in the the Package.appxmanifest I've set Toast Capable: YES.
Anyone knows how to solve this? Thanks
回答1:
The application may be throwing an exception in the background but since this is in the background you can not see it. The only way I have found to resolve this type of issue is adding logging functionality to the App so you will be able to see the exception
来源:https://stackoverflow.com/questions/24419727/toast-notification-geofence-windows-phone-8-1