UNUserNotificationCenterDelegate didReceive response not getting called

I am seeing a weird issue where on click of notification(Foreground and Background state),

func userNotificationCenter(_ center: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void)

is not getting called.But what makes this even more weird is that the other UNUserNotificationCenterDelegate function is getting called when notification is received:

func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)

I am getting this following warning in the console

Warning: UNUserNotificationCenter delegate received call to -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: but the completion handler was never called.

I do have delegate set properly.

UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: { (granted, error) in
                    if granted {
                        let center = UNUserNotificationCenter.current()
                        center.delegate = self
                    }
                })

Here is the implementation of didReceive method.

func userNotificationCenter(_ center: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void) {

        if response.actionIdentifier == UNNotificationDismissActionIdentifier {
            print ("Message Closed")
            }
        else if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
            print ("App is Open")
        }
        
        completionHandler()
    }

Please help me to solve this. Thanks.

iPhone 7, iOS 12

Posted on Feb 8, 2021 9:48 PM

Reply

Similar questions

There are no replies.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

UNUserNotificationCenterDelegate didReceive response not getting called

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.