Flutter - 警告:应用程序委托收到对 -application:didReceiveRemoteNotification:fetchCompletionHandler 的调用

问题描述 投票:0回答:1

每当我收到服务器的通知时,我都会遇到以下警告。我们正在从服务器发送静默推送通知。

从警告中,我可以了解到设备上正在接收通知,但没有从 iOS 端触发回调。

我对iOS开发不熟悉。我在这个问题上花了超过3天的时间。有谁知道如何解决这个问题吗?

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

ios flutter dart push-notification firebase-cloud-messaging
1个回答
0
投票

从警告本身我们可以了解到,通知已发送至 iOS 设备。但该通知不是由本机 iOS 端的 firebase 处理的。

因此,在本机端重写 didReceiveRemoteNotification 方法,并通过调用 firebase 方法通道方法将接收到的值传递给 flutter。

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)
}

参考:Github问题评论

© www.soinside.com 2019 - 2024. All rights reserved.