onNotification函数(回调)不会与FCMPlugin一起触发

时间:2019-06-09 16:09:47

标签: ios cordova cordova-plugin-fcm

我使用此插件将推送通知添加到我的iOS项目-> https://github.com/fechanique/cordova-plugin-fcm

我可以收到通知,然后单击打开应用程序。但是,当我从服务器发送带有参数的通知时,该通知不起作用(onNotification函数(回调)不会触发)。

我使用此结构从服务器发送通知:

    {
  "notification":{
    "title":"Notification title",
    "body":"Notification body",
    "sound":"default",
    "click_action":"FCM_PLUGIN_ACTIVITY",
    "icon":"fcm_push_icon"
  },
  "data":{
    "param1":"value1",
    "param2":"value2"
  },
    "to":"token_id",
    "priority":"high",
}

有人知道是什么问题吗?唯一的问题是onNotification函数。

 FCMPlugin.onNotification(function(data){
    if(data.wasTapped){
      console.log( JSON.stringify(data) );
    }else{
      console.log( JSON.stringify(data) );
    }
});

我的php代码,用于从服务器发送通知:

       $url = "https://fcm.googleapis.com/fcm/send";
$token = $fcmtokuser;
$serverKey = 'serverkey';
$body = "".$nottext."";
$notification = array( 'body' => $body,'title' => $title, 'click_action'=> 'FCM_PLUGIN_ACTIVITY', 'badge' => $totalbadgenum);
$datanot = array( 'param1' => $t4, 'param2' => 'newnot');
$arrayToSend = array('to' => $token,'data'=> $datanot, 'notification' => $notification,'priority'=>'high');
$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key='. $serverKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$response = curl_exec($ch);
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);

0 个答案:

没有答案