FCM将消息从php复制到iOS颤振应用程序

FCM将消息从php复制到iOS颤振应用程序,php,flutter,dart,firebase-cloud-messaging,Php,Flutter,Dart,Firebase Cloud Messaging,我将Firebase云消息用于颤振应用程序 我尝试用php代码触发推送通知。它给了我一个成功:1个结果,但在我的设备上,我总是收到2条标题和正文相同但消息ID不同的消息,这是由google firebase提供的 我反复检查,我只在服务器端触发此函数一次 我在服务器上的代码 $url = 'https://fcm.googleapis.com/fcm/send'; $msg = array ( 'body' => $message, 'ti

我将Firebase云消息用于颤振应用程序

我尝试用php代码触发推送通知。它给了我一个成功:1个结果,但在我的设备上,我总是收到2条标题和正文相同但消息ID不同的消息,这是由google firebase提供的

我反复检查,我只在服务器端触发此函数一次

我在服务器上的代码

$url = 'https://fcm.googleapis.com/fcm/send';
$msg = array
    (
          'body'  => $message,
          'title' => $title,
                  'badge' => 1,/*Default sound*/
                  'sound' => 'default',
    );
$fields = array
        (
            'registration_ids' => $id,
            'notification'  => $msg
        );

$fields = json_encode ( $fields );

$apiKey = 'XXXXXXX'; //IOS

$headers = array (
        'Authorization: key='.$apiKey,
        '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_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );

$result = curl_exec ( $ch );
curl_close ( $ch );
    echo $result;
我试图从终端触发这个,它工作正常,只发送了一条消息。我的终端代码:

DATA='{"notification": {"body": "this is a body","title": "this is a title"}, "priority": "high", "data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "1", "status": "done"}, "to": "MYDEVICETOKEN"}'
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=XXXXXXXXX"    

我有一个类似的问题,但它是在反应本地。也许它能帮助你。问题是有两个服务负责在AndroidManifest中接收通知\消息。

我也有类似的问题,但它是在React native中。也许它能帮助你。问题是有两个服务负责接收AndroidManifest中的通知\消息。

这目前看起来像是一个颤振问题。 作为目前的解决办法,您可以创建一个布尔值并按如下方式触发它:

class _SomethScreenState extends State<SomeScreen> {

  bool onNotificationTrigger = false;
...

_fcm.configure(
      onMessage: (Map<String, dynamic> response) async {
        setState(() {
          onNotificationTrigger = !onNotificationTrigger;

          if (onNotificationTrigger)
           // Do Something
        });
      },
...

目前,这似乎是一个棘手的问题。 作为目前的解决办法,您可以创建一个布尔值并按如下方式触发它:

class _SomethScreenState extends State<SomeScreen> {

  bool onNotificationTrigger = false;
...

_fcm.configure(
      onMessage: (Map<String, dynamic> response) async {
        setState(() {
          onNotificationTrigger = !onNotificationTrigger;

          if (onNotificationTrigger)
           // Do Something
        });
      },
...

对我来说,正在升级到:

颤振版本1.17.5 Firebase_消息:^6.0.16
对我来说,正在升级到:

颤振版本1.17.5 Firebase_消息:^6.0.16
不幸的是,我在iOS设备上也遇到了这个问题。不幸的是,我在iOS设备上也遇到了这个问题。您好,面临着同样的问题。您找到问题了吗?您是否尝试在web浏览器中调用?Chrome会触发两次代码,这就是消息重复的原因。你好,面临同样的问题。您找到问题了吗?您是否尝试在web浏览器中调用?Chrome会触发两次代码,这就是消息重复的原因。