[英]Push Notification Trigger on Windows Phone 8.1 Silverlight
I'm working on the "feature" the push notification trigger available in Windows phone 8.1. 我正在研究Windows Phone 8.1中可用的“功能”推送通知触发器。 My goal is to make this work with a Windows phone Silverlight 8.1 project.
我的目标是使此功能与Windows Phone Silverlight 8.1项目一起使用。 As far as I know, it should work based on my reading.
据我所知,它应该基于我的阅读。
After 2 days, I'm totally stuck. 2天后,我完全被卡住了。 No matter what i'm trying.
不管我在做什么。 When I send a raw notification to my app, my app is canceled and I'm back to the windows menu.
当我向应用程序发送原始通知时,我的应用程序被取消,并且返回到Windows菜单。
The output : The program '[1852] BACKGROUNDTASKHOST.EXE' has exited with code 1 (0x1). 输出:程序“ [1852] BackgroundTASKHOST.EXE”已退出,代码为1(0x1)。 The program '[2712] AgHost.exe' has exited with code 1 (0x1).
程序“ [2712] AgHost.exe”已退出,代码为1(0x1)。
State : 状态:
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!");
}
}
I have no clue about what I'm doing wrong. 我不知道我在做什么错。 Is there someone who make it works ?
有没有人使它起作用? (Not in theory) For information, I have 2 warnings that worrying me :
(理论上不是)为了提供信息,我有2条警告令我担心:
Found conflicts between different versions of the same dependent assembly. 发现相同从属程序集的不同版本之间存在冲突。 In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts;
在Visual Studio中,双击该警告(或选择它并按Enter)以解决冲突; otherwise, add the following binding redirects to the "runtime" node in the application configuration file:
否则,将以下绑定重定向添加到应用程序配置文件中的“运行时”节点:
Thanks in advance 提前致谢
I did finally make it works. 我终于做到了。
There was an error in my initial code I forgot to implement IBackgroundTask : 我的初始代码中有一个错误,我忘记了实现IBackgroundTask:
public sealed class Notification : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background starting...");
Debug.WriteLine("Background completed!");
}
}
And I had to make my Task async... 我不得不使我的任务异步...
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
}
Hope this'll help someone. 希望这会帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.