locked
How to access WPS notifications received by the UWP application? RRS feed

  • Question

  • User394095 posted

    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.

    Thursday, May 7, 2020 12:14 PM

Answers

  • User382871 posted

    How do I capture the notification tapped by the user? As I will require to navigate to certain pages based on the notification tapped. To navigate in Xamarin.Forms by clicking the notification, you can use MessagingCenter to call the navigation method in the native project. Try to override the OnActivated event to achieve this function, you can use ToastNotificationActivatedEventArgs in this method.

    Check the links: https://stackoverflow.com/questions/48321275/how-to-navigate-to-a-particular-page-when-user-taps-on-a-local-notification-in-x https://stackoverflow.com/questions/57924108/uwp-how-can-i-get-the-click-event-of-notification-from-notification-history

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, May 8, 2020 9:49 AM
  • User394095 posted

    @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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 3, 2020 9:46 AM

All replies

  • User382871 posted

    How do I capture the notification tapped by the user? As I will require to navigate to certain pages based on the notification tapped. To navigate in Xamarin.Forms by clicking the notification, you can use MessagingCenter to call the navigation method in the native project. Try to override the OnActivated event to achieve this function, you can use ToastNotificationActivatedEventArgs in this method.

    Check the links: https://stackoverflow.com/questions/48321275/how-to-navigate-to-a-particular-page-when-user-taps-on-a-local-notification-in-x https://stackoverflow.com/questions/57924108/uwp-how-can-i-get-the-click-event-of-notification-from-notification-history

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, May 8, 2020 9:49 AM
  • User394095 posted

    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?

    Monday, May 11, 2020 8:06 AM
  • User394095 posted

    @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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 3, 2020 9:46 AM