I'm trying to get raw push notifications to go to a background task. This already works when the app is in the foreground, so I know it's not anything with getting the notification delivered.
Here's the steps I used.
In the manifest:
<Extensions>
<Extension Category="windows.backgroundTasks"
EntryPoint="TestApp.BackgroundNotifications">
<BackgroundTasks>
<Task Type="pushNotification" />
</BackgroundTasks>
</Extension>
</Extensions>
The background class:
namespace TestApp {
public sealed class BackgroundNotifications : IBackgroundTask {
public void Run(IBackgroundTaskInstance taskInstance) {
Debug.WriteLine("Got background notification");
}
}
}
And then the registration:
BackgroundAccessStatus status =
await BackgroundExecutionManager.RequestAccessAsync();
BackgroundTaskBuilder taskBuilder =
new BackgroundTaskBuilder {
Name = "MyBackgroundNotifications",
TaskEntryPoint = "TestApp.BackgroundNotifications"
};
taskBuilder.SetTrigger(new PushNotificationTrigger());
BackgroundTaskRegistration myTask = taskBuilder.Register();
When I send a raw push notification I see this in the log but not my debug message:
The program '[16660] backgroundTaskHost.exe' has exited with code 1 (0x1).
Is there a step I'm missing?