Toast 通知和地理围栏 Windows Phone 8.1

2024-05-06

我的 Windows Phone 8.1 应用程序遇到一个奇怪的问题。 每当用户使用地理围栏靠近他感兴趣的点时,应用程序都会发送一条 toast 通知快速入门:设置地理围栏 http://msdn.microsoft.com/en-us/library/windowsphone/develop/dn322032.aspx和后台任务快速入门:在后台监听地理围栏事件 http://msdn.microsoft.com/en-us/library/windowsphone/develop/dn322031.aspx

这是后台任务(示例)

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 应用程序部署在设备上安装应用程序,则应用程序可以正常工作,并且使用相同模拟器。但是一旦上传到商店,我就下载了应用程序,Toa​​st、Geofence 或 BackgroundTask 就不再工作了(我猜问题是这三个之一,但我不知道谁是罪魁祸首:s)。 .toast 通知不会触发..

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

有人知道如何解决这个问题吗?谢谢


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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Toast 通知和地理围栏 Windows Phone 8.1 的相关文章

随机推荐