Search code examples
iosflutterdartpush-notificationfirebase-cloud-messaging

Flutter - Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler


I'm facing the below warning whenever I receive a notification from the server. We're sending a silent push notification from the server.

From the warning, I can understand that a notification is being received on the device, but a callback is not triggered from the iOS side.

I'm not familiar with iOS development. I'm spending more than 3 days on this issue. Anyone know how to resolve this issue?

Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.


Solution

  • From the warning itself we can understand that, notification is came to iOS device. But that notification is not handled by firebase in native iOS side.

    So overriding didReceiveRemoteNotification method in native side and passing the received values to flutter by calling firebase method channel method.

    Answer Reference: Github Issue Comment

    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        
        let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
        let channel = FlutterMethodChannel(name: "plugins.flutter.io/firebase_messaging", binaryMessenger: controller.binaryMessenger);
        let dictionary: NSDictionary = [
            "cm.message_id": "1234567890123456",
            "data": [
                "content_available":  userInfo["content_available"],
            ],
        ]
        channel.invokeMethod("Messaging#onMessage", arguments: dictionary)
    }