因为我已经一年多一科尔多瓦(7.1.0)应用两个iOS和Android依赖上的PhoneGap-插件推插件推送通知。
所有工作得很好,现在也工作正常,除了只有最后发送通知。
正如我的应用程序可以被设置为监视多个地方,它将使意义是只显示最后的通知,但至少有一个为每个选定的地方。
我想过用“标签”,但我试图把它在不同的地方都没有成功。
在这里,最起码的PHP代码我用它来发送通知:
$msg['tag']=$spotid; //tried on 2019 02 05: no success
$msg['sound']=$sound;
$msg['soundname']=$sound; //20180913
$msg['android_channel_id']=$sound; //20180913
$data = array
(
'Spot' => $spotname,
'rain' => $rain
);
$fields = array
(
'registration_ids' => $newId
'vibrate' => $vibration,
'priority' => 'high',
'data' => array_merge( $msg,$data ), //$data //20180913
'tag' => $spotid //tried on 2019 02 05: no success
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
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, json_encode( $fields ) );
$resultFCM = curl_exec($ch );
if ($resultFCM === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close( $ch );
任何建议?
编辑
futher测试后,我发现一些作品:
$msg['tag']=$spotid; //works if inserted in "notification"
$msg['sound']=$sound;
$msg['soundname']=$sound; //20180913
$msg['android_channel_id']=$sound; //20180913
$data = array
(
'Spot' => $spotname,
'rain' => $rain
);
$fields = array
(
'registration_ids' => $newId, //$registrationIds,
'vibrate' => $vibration,
'priority' => 'high',
'notification' => $msg, // 2019 attempt to group ONLY by spot. check if problems with iOS
'data' => array_merge( $msg,$data )
);
要注意的是,$味精必须完全重复的(而不是添加只是“标记”),否则从Android的通知将缺少图标,声音等
它的工作原理和团体的通知
问题是,点击通知它不会打开了应用程序:我在这里检查的一些建议:
但不知道如何应用在科尔多瓦的应用程序...
编辑2
它结束了比我想象的要简单得多。
首先,PhoneGap的-推插件不“喜欢”的“通知”设置和副作用有关使用它的一个,就是它不通知操作的点击关联到打开的背景(或关闭)的应用程序这反而会发生把“数据”在有效载荷(没有“通知”)。
“电子标签”(这有助于分组)支持在“通知”仅(似乎),这是一个不走我的情况。
尽管如此,推插件的文档中有关于如何团的精彩暗示其中的“数据”数组的一个元素:
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#stacking
https://github.com/phonegap/phonegap-plugin-push/issues/2523
下面我上面的例子,其中分组元素是整数$ spotid我刚刚加入“notId” => $ spotid:
$msg['sound']=$sound;
$msg['soundname']=$sound; //20180913
$msg['android_channel_id']=$sound; //20180913
$data = array
(
'Spot' => $spotname,
'rain' => $rain,
'notId' => $spotid // 2019 attempt to group ONLY by spot. check if problems with iOS
);
$fields = array
(
'registration_ids' => $newId, //$registrationIds,
'vibrate' => $vibration,
'priority' => 'high'
'data' => array_merge( $msg,$data )
);
notId到“数据”让正常组。
按照在EDIT2注释,对于科尔多瓦-插件推,加入“notId”到“数据”允许才能正常组(和/或单独在我的情况)的通知。见上文编辑的详细信息