即使我(认为)满足文档中指定的所有条件,FCM onbackgroundmessage 也无法在应用程序上运行已终止。 这是正在发送的示例消息
<?php
function sendNotification(){
$server_token="AAAAksZAlDc:APA91bGLAfguJLdXmz65F-server token";
$headers=array("Content-Type: application/json", "Authorization: key=$server_token");
$url="https://fcm.googleapis.com/fcm/send";
$ch= curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
$kita=time();
$uid="dELAY-CRRm6z4ICpQP user token";
//$post_data= array("to"=> "$uid", "notification"=> array("title"=> "server title", "body"=>"Body from the server"));
$kita= date("jS F Y h:i:a", time());
$post_data= array("to"=> "/topics/sample_topic", "notification"=> array("title"=> "server title at $kita" , "body"=>"Body from the server"));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resp= curl_exec($ch);
curl_close($ch);
echo "<p>Response is $resp</p>";
}
sendNotification();
?>
然后在我的 Flutter 应用中等待通知
FirebaseMessaging.onBackgroundMessage(fcmBGMsgs);
Future<void> fcmBGMsgs(remoteMessage){
//defined outside every class
}
如果您有示例工作演示,请分享