Windows Phone 8.1 Silverlight 上的推送通知触发器
Push Notification Trigger on Windows Phone 8.1 Silverlight
我正在研究 "feature" Windows phone 8.1 中可用的推送通知触发器。我的目标是使这项工作与 Windows phone Silverlight 8.1 项目一起使用。据我所知,它应该基于我的阅读。
2 天后,我完全被困住了。不管我在尝试什么。当我向我的应用程序发送原始通知时,我的应用程序被取消并且我返回到 windows 菜单。
输出:
程序“[1852] BACKGROUNDTASKHOST.EXE”已退出,代码为 1 (0x1)。
程序“[2712] AgHost.exe”已退出,代码为 1 (0x1)。
状态:
- 应用收到通知。它触发 OnPushNotificationReceived。 (此事件后,该应用被取消)
- 推送通知任务已声明,入口点定义为Push.Notification.
- 我为 Windows phone 8.1 创建了一个 Windows 运行时组件,以便 运行 后台任务。
- 后台任务注册成功
private async void RegisterBackgroundTask()
{
UnregisterBackgroundTask(taskName);
BackgroundAccessStatus backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundStatus != BackgroundAccessStatus.Denied && backgroundStatus != BackgroundAccessStatus.Unspecified)
{
try
{
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = taskName;
PushNotificationTrigger trigger = new PushNotificationTrigger();
taskBuilder.SetTrigger(trigger);
taskBuilder.TaskEntryPoint = "Push.Notification";
BackgroundTaskRegistration task = taskBuilder.Register();
}
catch (Exception ex)
{ }
}
}
- 后台任务:
public sealed class Notification
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background starting...");
Debug.WriteLine("Background completed!");
}
}
我不知道自己做错了什么。
有没有人让它起作用? (理论上没有)
有关信息,我有 2 个令我担心的警告:
- 我的 2 个项目的流程架构不匹配。我的 windows phone 项目使用 "Any CPU"(可以 "t change that). My windows runetime component project use "ARM)。如果我使用 "Any CPU" wor 我的 WinRT,我得到一个错误:
/platform:anycpu32bitpreferred 只能与 /t:exe、/t:winexe 和 /t:appcontainerexe 一起使用
- 这 2 个项目的依赖程序集存在冲突。好像是
发现同一依赖程序集的不同版本之间存在冲突。在Visual Studio中双击此警告(或select并回车)修复冲突;否则,将以下绑定重定向添加到应用程序配置文件中的 "runtime" 节点:
提前致谢
我终于成功了。
我的初始代码有一个错误我忘了实现 IBackgroundTask :
public sealed class Notification : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background starting...");
Debug.WriteLine("Background completed!");
}
}
而且我不得不让我的任务异步...
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
// perform your async task and then call deferral complete
await Test();
deferral.Complete();
}
private static async Task Test()
{
//TODO with an await
}
希望这会对某人有所帮助。
我正在研究 "feature" Windows phone 8.1 中可用的推送通知触发器。我的目标是使这项工作与 Windows phone Silverlight 8.1 项目一起使用。据我所知,它应该基于我的阅读。
2 天后,我完全被困住了。不管我在尝试什么。当我向我的应用程序发送原始通知时,我的应用程序被取消并且我返回到 windows 菜单。
输出: 程序“[1852] BACKGROUNDTASKHOST.EXE”已退出,代码为 1 (0x1)。 程序“[2712] AgHost.exe”已退出,代码为 1 (0x1)。
状态:
- 应用收到通知。它触发 OnPushNotificationReceived。 (此事件后,该应用被取消)
- 推送通知任务已声明,入口点定义为Push.Notification.
- 我为 Windows phone 8.1 创建了一个 Windows 运行时组件,以便 运行 后台任务。
- 后台任务注册成功
private async void RegisterBackgroundTask()
{
UnregisterBackgroundTask(taskName);
BackgroundAccessStatus backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundStatus != BackgroundAccessStatus.Denied && backgroundStatus != BackgroundAccessStatus.Unspecified)
{
try
{
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = taskName;
PushNotificationTrigger trigger = new PushNotificationTrigger();
taskBuilder.SetTrigger(trigger);
taskBuilder.TaskEntryPoint = "Push.Notification";
BackgroundTaskRegistration task = taskBuilder.Register();
}
catch (Exception ex)
{ }
}
}
- 后台任务:
public sealed class Notification
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background starting...");
Debug.WriteLine("Background completed!");
}
}
我不知道自己做错了什么。 有没有人让它起作用? (理论上没有) 有关信息,我有 2 个令我担心的警告:
- 我的 2 个项目的流程架构不匹配。我的 windows phone 项目使用 "Any CPU"(可以 "t change that). My windows runetime component project use "ARM)。如果我使用 "Any CPU" wor 我的 WinRT,我得到一个错误: /platform:anycpu32bitpreferred 只能与 /t:exe、/t:winexe 和 /t:appcontainerexe 一起使用
- 这 2 个项目的依赖程序集存在冲突。好像是
发现同一依赖程序集的不同版本之间存在冲突。在Visual Studio中双击此警告(或select并回车)修复冲突;否则,将以下绑定重定向添加到应用程序配置文件中的 "runtime" 节点:
提前致谢
我终于成功了。
我的初始代码有一个错误我忘了实现 IBackgroundTask :
public sealed class Notification : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background starting...");
Debug.WriteLine("Background completed!");
}
}
而且我不得不让我的任务异步...
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
// perform your async task and then call deferral complete
await Test();
deferral.Complete();
}
private static async Task Test()
{
//TODO with an await
}
希望这会对某人有所帮助。