• <tfoot id='cQ1Q4'></tfoot>

    <small id='cQ1Q4'></small><noframes id='cQ1Q4'>

      <bdo id='cQ1Q4'></bdo><ul id='cQ1Q4'></ul>

      <legend id='cQ1Q4'><style id='cQ1Q4'><dir id='cQ1Q4'><q id='cQ1Q4'></q></dir></style></legend>
    1. <i id='cQ1Q4'><tr id='cQ1Q4'><dt id='cQ1Q4'><q id='cQ1Q4'><span id='cQ1Q4'><b id='cQ1Q4'><form id='cQ1Q4'><ins id='cQ1Q4'></ins><ul id='cQ1Q4'></ul><sub id='cQ1Q4'></sub></form><legend id='cQ1Q4'></legend><bdo id='cQ1Q4'><pre id='cQ1Q4'><center id='cQ1Q4'></center></pre></bdo></b><th id='cQ1Q4'></th></span></q></dt></tr></i><div id='cQ1Q4'><tfoot id='cQ1Q4'></tfoot><dl id='cQ1Q4'><fieldset id='cQ1Q4'></fieldset></dl></div>

        FCM 推送通知问题:“错误":“未注册"

        时间:2024-08-22
      1. <tfoot id='dGqvk'></tfoot>

          <small id='dGqvk'></small><noframes id='dGqvk'>

          <legend id='dGqvk'><style id='dGqvk'><dir id='dGqvk'><q id='dGqvk'></q></dir></style></legend>
          1. <i id='dGqvk'><tr id='dGqvk'><dt id='dGqvk'><q id='dGqvk'><span id='dGqvk'><b id='dGqvk'><form id='dGqvk'><ins id='dGqvk'></ins><ul id='dGqvk'></ul><sub id='dGqvk'></sub></form><legend id='dGqvk'></legend><bdo id='dGqvk'><pre id='dGqvk'><center id='dGqvk'></center></pre></bdo></b><th id='dGqvk'></th></span></q></dt></tr></i><div id='dGqvk'><tfoot id='dGqvk'></tfoot><dl id='dGqvk'><fieldset id='dGqvk'></fieldset></dl></div>
                <bdo id='dGqvk'></bdo><ul id='dGqvk'></ul>

                    <tbody id='dGqvk'></tbody>
                1. 本文介绍了FCM 推送通知问题:“错误":“未注册"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了使用 FCM 向 Android 发送推送通知的奇怪问题.

                  <块引用>

                  目标:- 发送推送通知时出错

                  以下是我确实具有向 Android 发送推送通知功能的场景

                   公共静态函数 SendMultipleNotificationAndroid($groups){//你的 api 密钥 SERVER API KEY$apiKey = Yii::$app->params['android_api_key'];$url = 'https://fcm.googleapis.com/fcm/send';$标头=数组('授权:密钥 =' .$apiKey,'内容类型:应用程序/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_SSL_VERIFYPEER, false);foreach($groups 作为 $resG){$users = $resG['users'];$msg = $resG['message'];$type = $resG['notification_type'];$notification_data = $resG['notification_data'];$deviceTokens = [];foreach($users 作为 $resUser){$deviceTokens[] = $resUser['device_token'];//添加好友徽章计数+1Common::AddRemoveBadgeCount($resUser['user_id']);}if(!empty($deviceTokens)){$字段 = 数组('registration_ids' =>$deviceTokens,'优先级' =>'高的','collapse_key' =>$resG['notification_type'],'time_to_live' =>2419200,点击动作"=>通知列表活动",'数据' =>[标题"=>项目名称",身体"=>$resG['消息'],action_tag"=>$resG['notification_type'],消息"=>$resG['消息'],'notification_type' =>$类型,'notification_data' =>$通知数据,'声音' =>'默认',]);//打印结果p($ch,0);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));curl_exec($ch);}}curl_close($ch);}

                  所以问题是当我发送单个通知时它工作正常,但是当我发送多个通知时我每次都收到错误

                  Resource id #5

                  {multicast_id":4818908994630396118,success":1,failure":1,canonical_ids":0,results";:[{错误":未注册"},{message_id":0:1487136045570022%c3bae3c6002e9358"}]}<pre>Resource id #5</pre>{multicast_id":5218359780835228544,success":1,failure":1,canonical_ids":0,results":[{";错误":"NotRegistered"},{"message_id":"0:1487136046618669%c3bae3c6002e9358"}]}

                  当我们调试代码时,我们的数据库中确实有设备令牌,没有防火墙会停止发送推送通知.

                  每次我调用上面的函数时都会得到

                  错误":未注册"

                  解决方案

                  根据文档,因为移动设备测试不再安装您的应用程序

                  <块引用>

                  如果未注册,则应从您的服务器数据库,因为该应用程序已从设备,或客户端应用未配置为接收消息.

                  I am getting weird issue of sending push notification to Android using FCM.

                  Goal :- Having error while sending push notification

                  Below is the scenario I do have function for sending push notification to Android

                   public static function SendMultipleNotificationAndroid($groups)
                      {
                          //your api key SERVER API KEY
                          $apiKey = Yii::$app->params['android_api_key'];
                          $url = 'https://fcm.googleapis.com/fcm/send';    
                          $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_SSL_VERIFYPEER, false);
                          
                          foreach($groups as $resG){
                              $users  = $resG['users'];                        
                              $msg    =   $resG['message'];
                              $type    =   $resG['notification_type'];
                              $notification_data    =   $resG['notification_data'];
                  
                              $deviceTokens = [];
                              foreach($users as $resUser){
                                  $deviceTokens[] = $resUser['device_token'];
                                  //Add  Friend badge count +1
                                  Common::AddRemoveBadgeCount($resUser['user_id']);
                              }
                              if(!empty($deviceTokens)){
                                  $fields = array(
                                      'registration_ids' => $deviceTokens,
                                      'priority'     => 'high', 
                                      'collapse_key' => $resG['notification_type'],   
                                      'time_to_live' => 2419200,     
                                      "click_action" =>"NotificationListingActivity",     
                                      'data'         => [                  
                                          "title"             => "ProjectName",
                                          "body"              => $resG['message'],
                                          "action_tag"        => $resG['notification_type'],
                                          "message"           => $resG['message'],
                                          'notification_type' => $type,
                                          'notification_data' => $notification_data,
                                          'sound'             => 'default',
                                      ]
                                  );
                                  //Print result 
                                  p($ch,0);
                                  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
                                  curl_exec($ch);
                              }            
                          }
                          curl_close($ch);
                      }
                  

                  So the issue is when I send single notification it works fine but when I send multiple notification I got error every time

                  <pre>Resource id #5</pre>{"multicast_id":4818908994630396118,"success":1,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"},{"message_id":"0:1487136045570022%c3bae3c6002e9358"}]}
                  
                  <pre>Resource id #5</pre>{"multicast_id":5218359780835228544,"success":1,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"},{"message_id":"0:1487136046618669%c3bae3c6002e9358"}]}
                  

                  As we debug the code we do have device token in our database no firewall which stops sending push notifications.

                  Every time I call above function I get

                  "error":"NotRegistered"
                  

                  解决方案

                  According to the doc its because the mobile device testing does not have your app installed anymore

                  If it is NotRegistered, you should remove the registration ID from your server database because the application was uninstalled from the device, or the client app isn't configured to receive messages.

                  这篇关于FCM 推送通知问题:“错误":“未注册"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:通过 cURL/PHP 发送时设备上未收到 Firebase 通知 下一篇:将 GCM 迁移到 FCM,我应该/可以保留当前 GCM 服务器端的代码吗?

                  相关文章

                  • <bdo id='lO4hA'></bdo><ul id='lO4hA'></ul>

                2. <legend id='lO4hA'><style id='lO4hA'><dir id='lO4hA'><q id='lO4hA'></q></dir></style></legend>
                  <i id='lO4hA'><tr id='lO4hA'><dt id='lO4hA'><q id='lO4hA'><span id='lO4hA'><b id='lO4hA'><form id='lO4hA'><ins id='lO4hA'></ins><ul id='lO4hA'></ul><sub id='lO4hA'></sub></form><legend id='lO4hA'></legend><bdo id='lO4hA'><pre id='lO4hA'><center id='lO4hA'></center></pre></bdo></b><th id='lO4hA'></th></span></q></dt></tr></i><div id='lO4hA'><tfoot id='lO4hA'></tfoot><dl id='lO4hA'><fieldset id='lO4hA'></fieldset></dl></div>

                      <tfoot id='lO4hA'></tfoot>

                      <small id='lO4hA'></small><noframes id='lO4hA'>