Forum Xamarin.iOS

ReceivedRemoteNotification and DidReceiveRemoteNotification never get called

Hi,

We implemented remote push notifications in our app. What we would like to achieve is that when our app is in the background, a remote notification comes in, the user clicks on the notification, we perform some tasks based on the notification information. I noticed that when the app was in the background, when a notification came in, in Appdelegate, DidReceiveRemoteNotification and ReceivedRemoteNotification never get called. There's no way for me to get the notification from userInfo. Has anyone experienced this issue? Is this a bug? Any help is greatly appreciated!

Thanks,
Lichang

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Have you implemented the IUNUserNotificationCenterDelegate for iOS 10+? If so, DidReceiveRemoteNotification and ReceivedRemoteNotification will never be triggered when user click the notification to open your app.
    After setting the UNUserNotificationCenter.Current.Delegate = this; in your AppDelegate you should register the event below to handle the click event:

    [Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
    public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
    {
        var userInfo = response.Notification.Request.Content.UserInfo;
        completionHandler();
    }
    
Sign In or Register to comment.