Ionic 4中的自动更新徽章编号
我正在使用离子4 Cordova插件FCM。 除非我刷新该应用程序,否则我的应用程序通知工作完美,但徽章编号不会增加。 因此,我的问题是如何在没有iOS中刷新应用程序的情况下增加徽章计数?
我的通知有效载荷格式
<?php
function send_notification ($token, $message, $title)
{
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $token,
'notification' => array('title' => $title, 'body' => $message ),
'data' => array('message' => $message, 'title' => $title ),
'sound' => 'default',
'badge' => 1
);
$headers = array(
'Authorization:key=AAAAF.....,
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
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_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$message=$_POST["message"];
$title=$_POST["title"];
include_once 'config.php';
$sql = "SELECT mem_tokenid FROM user";
$result = mysqli_query($conn,$sql);
//var_dump(result);
if(mysqli_num_rows($result) > 0 ){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["mem_tokenid"];
}
}
var_dump($tokens);
mysqli_close($conn);
$message = $message;
$title = $title;
$message_status = send_notification($tokens, $message, $title);
echo $message_status;
?>
我在这里做错了吗?
I'm using ionic 4 cordova plugin FCM.
My app notification working perfect but badge number not increase unless I refresh the app.
So, my question is how to increment badge count without refresh app in ios?
My Notification payload format is
<?php
function send_notification ($token, $message, $title)
{
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $token,
'notification' => array('title' => $title, 'body' => $message ),
'data' => array('message' => $message, 'title' => $title ),
'sound' => 'default',
'badge' => 1
);
$headers = array(
'Authorization:key=AAAAF.....,
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
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_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$message=$_POST["message"];
$title=$_POST["title"];
include_once 'config.php';
$sql = "SELECT mem_tokenid FROM user";
$result = mysqli_query($conn,$sql);
//var_dump(result);
if(mysqli_num_rows($result) > 0 ){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["mem_tokenid"];
}
}
var_dump($tokens);
mysqli_close($conn);
$message = $message;
$title = $title;
$message_status = send_notification($tokens, $message, $title);
echo $message_status;
?>
Do I did something wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论