Ionic 4中的自动更新徽章编号

发布于 2025-02-04 20:00:18 字数 2078 浏览 3 评论 0原文

我正在使用离子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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文