【发布时间】:2015-03-03 02:59:28
【问题描述】:
我将 Windows phone 8 应用升级到 8.1 silverlight。但是在使用地理围栏时,我想举杯祝酒。所以我写了这段代码
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);
}
}
但是在认证过程中它说
此应用程序类型不支持此 API - Api=Windows.UI.Notifications.ToastNotification。模块=。 文件=GeofenceTask.winmd。
之后我做了一些研究,发现 this answer 上面写着
如果你想使用 Windows.UI.Notifications,你必须选择 WNS 否则你有使用 ShellToast
所以我使用 MPN 是因为 Azure 移动服务不支持 WP8.1 silverlight 应用程序的 WNS。
通知中心 Windows Phone SDK 不支持将 WNS 与 Windows Phone 8.1 Silverlight 应用程序。
所以我认为在这种情况下我应该使用 ShellToast。但现在我走到了真正的死胡同。 Windows 运行时组件项目不支持 ShellToast。我没有所需的正确参考。即,Microsoft.Phone.Shell。如果我添加
Using Microsoft.Phone.Shell;
“电话”带有红色下划线。我该怎么办?
更新:
我尝试从 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0 添加 Microsoft.phone.dll
但我在定义 ToastShell 时遇到错误,其中显示:
“System.InvalidProgramException”类型的异常发生在 GeofenceTask.winmd 但未在用户代码中处理
附加信息:公共语言运行时检测到无效 程序。
【问题讨论】:
标签: c# silverlight windows-phone-8.1 background-task