You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase跨Android/iOS推送仅单设备接收问题求助

Troubleshooting Firebase Push Notifications (Only One Device Receives Them)

Hey there! Let's break down why only one device is getting your notifications and fix it step by step.

The Core Issue

From your code snippet, it looks like you're handling a single device type and token at a time, but you mentioned you have an array of device IDs paired with their types. The most likely problem is that you're not iterating through every entry in that array—you're only processing one device instead of all of them.

Fix: Iterate Through Your Device Array

First, let's assume your device array follows a structure like this (adjust to match your actual data):

$deviceList = [
    ['type' => 'iOS', 'token' => 'apple_device_token_123'],
    ['type' => 'Android', 'token' => 'android_fcm_token_456'],
    ['type' => 'iOS', 'token' => 'apple_device_token_789']
];

Now, loop through each device in the array and send the notification accordingly. I added a lowercase conversion to avoid case-mismatch issues (since your original code checks for "ios" but your device type might be stored as "iOS"):

$message = "Your notification content here";

foreach ($deviceList as $device) {
    $deviceType = strtolower($device['type']);
    $deviceToken = $device['token'];

    if ($deviceType === "ios") {
        $this->send_ios_notfication($deviceToken, $message, 'New Message');
    } elseif ($deviceType === "android") {
        $this->send_android_notfication($deviceToken, $message, 'New Message');
    }
}

Additional Checks to Ensure All Devices Receive Notifications

  • Validate Token Validity: Tokens can expire (iOS APNs tokens) or become invalid (Android FCM tokens after app uninstall/reinstall). Add logging inside your send_ios_notfication and send_android_notfication methods to capture Firebase/APNs responses—this will tell you if certain tokens are failing.
  • Check Method Implementation: Make sure your notification methods aren't stopping execution early (e.g., no unexpected return statements that exit the loop before processing all devices).
  • Batch Sending Optimization: For better performance, consider using Firebase's batch messaging APIs instead of sending individual requests. Android FCM supports sending to up to 500 tokens in one request, and iOS APNs also allows bulk payloads.

内容的提问来源于stack exchange,提问作者Vishal Hira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:46:58