1
我試圖讓原始推送通知去後臺任務。這在應用程序處於前臺時已經可以工作,所以我知道這與通知交付沒有任何關係。UWP背景原始推送通知
下面是我使用的步驟。
在清單:
<Extensions>
<Extension Category="windows.backgroundTasks"
EntryPoint="TestApp.BackgroundNotifications">
<BackgroundTasks>
<Task Type="pushNotification" />
</BackgroundTasks>
</Extension>
</Extensions>
背景類:
namespace TestApp {
public sealed class BackgroundNotifications : IBackgroundTask {
public void Run(IBackgroundTaskInstance taskInstance) {
Debug.WriteLine("Got background notification");
}
}
}
然後登記:
BackgroundAccessStatus status =
await BackgroundExecutionManager.RequestAccessAsync();
BackgroundTaskBuilder taskBuilder =
new BackgroundTaskBuilder {
Name = "MyBackgroundNotifications",
TaskEntryPoint = "TestApp.BackgroundNotifications"
};
taskBuilder.SetTrigger(new PushNotificationTrigger());
BackgroundTaskRegistration myTask = taskBuilder.Register();
當我發送原始推送通知我在看到這日誌但不是我的調試信息:
The program '[16660] backgroundTaskHost.exe' has exited with code 1 (0x1).
有沒有我失蹤的一步?
是的,就是這樣。我不明白它必須在自己的項目中。 – JOTN