吐司通知& Geofence Windows Phone 8.1

时间:2014-06-25 22:36:04

标签: c# windows-phone-8 toast windows-phone-8.1 winrt-component

我的Windows Phone 8.1应用程序遇到了一个奇怪的问题。 每次用户使用Geofence Quickstart: Setting up a geofence时,他都会在他感兴趣的点附近发送一个Toast通知 和BackgroundTask Quickstart: Listening for geofence events in the background

这是后台任务(示例)

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);

}

现在的问题是,如果我从VS运行应用程序一切正常并且一旦进入特定区域就会触发Toast ...如果我使用Windows Phone应用程序部署在设备上安装应用程序,该应用程序工作正常,和使用模拟器相同。但是一旦上传到商店,我已经下载了应用程序和Toast,Geofence或BackgroundTask不再工作(我猜问题是这三个中的一个,但我不知道谁是罪魁祸首:s)..吐司通知不会触发...

我还注意到我的应用程序未列在“通知+操作”设置中,但在Package.appxmanifest中我设置了Toast Capable: YES

任何人都知道如何解决这个问题?感谢

1 个答案:

答案 0 :(得分:1)

应用程序可能会在后台抛出异常,但由于这是在后台,您无法看到它。我发现解决此类问题的唯一方法是向应用程序添加日志记录功能,以便您能够看到异常