Open Diegorro98 opened 1 year ago
@bpulliam Any updates on this? I need a way to update the channel whenever the app updates (so the update background task is launched).
Another idea I had was to use Launcher.LaunchUriAsync
to open the app and update the registration, but it raises an InvalidOperationException
...
Btw, inspecting a little bit deeper the stack trace, I realized that the exception is launched when using PushNotificationManager.Default
(So Default
getter is called).
Stacktrace:
at WinRT.ExceptionHelpers.< ThrowExceptionForHR>g_Throw|39_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32hr)
at ABI.Microsoft.Windows.PushNotifications.IPushNotificationManagerStaticsMethods.get_Default(IObjectReference _obj)
at Microsoft.Windows.PushNotifications.PushNotificationManager.get_Default()
at App.BackgroundTasks.BackgroundTask.Run(IBackgroundTaskInstance taskInstance)
Describe the bug
I'm trying to create a flow where a background task updates the push notification channel when the app is updated. The background task runs fine, but when the task calls to
CreateChannelAsync
, it produces the following exception:Steps to reproduce the bug
In a project with a background task, in the background task project:
Run
method to the following:Expected behavior
It should get the channel URI when the background task is executed so that when the app is updated, because the channel is expired, the channel can be updated automatically. It should get it just like it does with the same instructions at the main app project, which works fine and creates a channel that allows me to send push notifications by following the instructions from this resource: Quickstart: Push notifications in the Windows App SDK
NuGet package version
Windows App SDK 1.3.2: 1.3.230602002
Packaging type
Packaged (MSIX)
Windows version
Insider Build (10.0.22631)
IDE
Visual Studio 2022
Additional context
I also tried with
PushNotificationChannelManager
:and
The first option was able to return an URI, but when trying to send the notification, it returned a 403 HTTP error. The second raised the following exception:
I got the idea to update the push notification channel when the update task is triggered from this resource: Run background task when your UWP app is updated