首页 > 解决方案 > Firebase 推送通知 - 未接收

问题描述

我有 PHP codeigniter 作为后端服务器将推送通知发送到 iOS 和 Android 设备。数据库中有超过 500 个用户使用他们的 FCM 令牌。在发送通知时,某些设备有时会收到通知,而其他设备每次都会收到通知。

public function sendNotification($data) {
    $apiKey = FCM_KEY;
    $client = new Client();
    $client->setApiKey($apiKey);
    $client->injectHttpClient(new \GuzzleHttp\Client());
    $note = new Notification($data['subject'], $data['message'], $is_silent);

    $message = new Message();
    $message->addRecipient(new Device($data['token']));
    $note->setIcon('notification_icon_resource_name')
                ->setBadge($data['total_notification_count'])
                ->setAndroidPriority('high')
                ->setSound('default')
                ->setContentAvailable(1);
    $message->setNotification($note);
    $message->setPriority(10);
    $message->setData(array('title' => $data['subject'], 'body' => $data['message']));
    $response = $client->send($message, $data['type']);
    return $response->getStatusCode();
}

是否有任何机制可以从 FCM 获取通知失败并仅为这些用户重试那些通知发送。

标签: phpandroidioscodeigniterfirebase-cloud-messaging

解决方案


推荐阅读