Laravel Firebase 数据消息在颤振 onBackgroundMessage 中不起作用

时间:2021-07-26 14:08:56

标签: laravel firebase flutter dart firebase-cloud-messaging

         $fields = array(
                "to" => $login_device_token->token,

                "notification" => array(
                    "title" => 'Call',
                    "click_action" =>'FLUTTER_NOTIFICATION_CLICK'),
                "data" => array(
                    "type" => $msg_type,
                    "id" => $msg_id,
                    "sub_no" => $sub_no,
                    "name" => $name,
                    "image" => $image,

                ),
                "content_available" =>true,
            );

            $headers = array(
                'Authorization: key=KEY',
                'Content-Type:application/json'
            );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
            $result = curl_exec($ch);
            curl_close($ch);

我通过 curl 将 FCM Data msg 发送到 Flutter App,我用它来赶上

onBackgroundMessage: (Map<String, dynamic> message) async {
            print('onBackgroundMessage: $message');
           }

但它不工作颤振。它转到 OnLaunch、OnResume 和 OnMessage 而不是 onBackgroundMessage。当应用程序处于终止模式时,它不起作用。

0 个答案:

没有答案