Forum Xamarin.Forms

How to access WPS notifications received by the UWP application?

Goutham_HasProblemsGoutham_HasProblems Member ✭✭✭
edited May 7 in Xamarin.Forms

Following this MSD I have implemented WPS push notification support for my UWP application. In the case of Android, we have a

public override async void OnMessageReceived(RemoteMessage message)

method which is going to capture the pushed FCM notification and we are able to add Pending intents and have functionalities like navigating to a specific page on tap of a certain notification implemented. Likewise in the case of iOS, we have a

[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)

to intercept any notification interaction from the user, such as taps, or action button interaction and handle them accordingly.

In UWP, we have a

toast.Activated

event, to which we can assign a handler to do whatever is it we want to achieve when the ToastNotification is interacted with.
Unfortunately, this requires me to actually create a ToastNotification to be able to assign an event handler to it.

But as stated in the Microsoft documentation, I need not have any method to intercept the push notification and create a ToastNotification. The Push notification banner is automatically displayed.

How do I capture the notification tapped by the user? As I will require to navigate to certain pages based on the notification tapped.

Best Answers

Answers

  • Goutham_HasProblemsGoutham_HasProblems Member ✭✭✭
    edited May 11

    Hey Jarvan, thanks for responding.
    After adding these:

    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
    var hub = new NotificationHub("<my hub name>", "<my DefaultListenSharedAccessSignature connection string>");
    var result = await hub.RegisterNativeAsync(channel.Uri);
    

    My UWP application begins to receive WPS push notifications. On tap of any of the received notification
    protected override void OnActivated(IActivatedEventArgs e) gets triggered but I don't receive any e as ToastNotificationActivatedEventArgs.

    I have attached the sample payload. Is there any modification required with my payload?

  • Goutham_HasProblemsGoutham_HasProblems Member ✭✭✭
    edited August 3 Accepted Answer

    @YelinZh said:
    Try to override the OnActivated event to achieve this function, you can use ToastNotificationActivatedEventArgs in > this method.

    We needed to use a ToastGeneric XML payload to invoke this method on tap of the notification. That was the issue.

Sign In or Register to comment.