Getting below error when a local notification is tapped and -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: is not getting called to handle the notification tap action. (FYI App is in foreground and this is local notification)

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

Code:

func registerForRemoteNotifications() {
    let center  = UNUserNotificationCenter.current()
    center.delegate = self
    center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
        if error == nil {
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }
}

extension PushNotificationManager: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        print("User Info = ",notification.request.content.userInfo)
        completionHandler([.alert, .badge, .sound])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        if appLoaded {
            handleNotificationForActiveState(userInfo: userInfo)
        } else {
            handleNotificationForInactiveState(userInfo: userInfo)
        }
        
        completionHandler()
    }
}

Getting below error when a local notification is tapped and -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: is not getting called to handle the notification tap action. (FYI App is in foreground and this is local notification)

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

Code:

func registerForRemoteNotifications() {
    let center  = UNUserNotificationCenter.current()
    center.delegate = self
    center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
        if error == nil {
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }
}

extension PushNotificationManager: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        print("User Info = ",notification.request.content.userInfo)
        completionHandler([.alert, .badge, .sound])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        if appLoaded {
            handleNotificationForActiveState(userInfo: userInfo)
        } else {
            handleNotificationForInactiveState(userInfo: userInfo)
        }
        
        completionHandler()
    }
}
0

There are 0 best solutions below