【问题标题】:Separate Notifications do not appear on a same device subscribed to a topic订阅主题的同一设备上不会出现单独的通知
【发布时间】:2021-11-25 06:59:56
【问题描述】:

当我通过使用 FCM 订阅主题的 api 在循环中推送多个通知时,以前的通知被我的 android 设备上的新通知取代。有没有办法分别推送多个通知。我正在使用 PHP Curl 请求。

foreach ($result as $item)
{
                    $message = array
                    (
                        'body' => "Details:".$item['tagid'],
                        'title' => "Tag:".$item['event'],
                        'key1' => "NotificationActivity"
                    );

                    $fields = array(
                        'to' => '/topics/all',
                        'data' => array
                        (
                            'message' => $message
                        ),
                    );
                    $headers = array
                    (
                        'Authorization: key=' . API_ACCESS_KEY,
                        'Content-Type: application/json'
                    );

                    $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));
                    $result = curl_exec($ch);
                    curl_close($ch);
                }

【问题讨论】:

    标签: php android firebase-cloud-messaging google-cloud-messaging


    【解决方案1】:

    我的 Firebase 服务出现问题。不基于 id 识别通知。 问题是,我在 id 字段中传递了 0。 notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

    设置每个通知的唯一ID后,它就可以工作了:

    notificationManager.notify(id /* ID of notification */, notificationBuilder.build());
    

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      • 2020-09-18
      • 2014-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多