I'm working on the "feature" the push notification trigger available in Windows phone 8.1. My goal is to make this work with a Windows phone Silverlight 8.1 project. As far as I know, it should work based on my reading.
After 2 days, I'm totally stuck. 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.
The output : The program '[1852] BACKGROUNDTASKHOST.EXE' has exited with code 1 (0x1). The program '[2712] AgHost.exe' has exited with code 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 :
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; 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 :
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.