Only-data messages being collapsed and dropped in iOS

I want to send multiple data messages to my flutter app. I was working with notifications as they were sent in all states (foreground, background, terminated) but found that they are being collapsed. I switched to use only-data messages and after some code modification, it works flawlessly on Android when the app is in any condition, I always receive the data message. Even if the user has no internet connection and multiple messages are sent, each one will be received after reconnecting. When testing this on iOS, I ran the app in release mode as I did in Android and everything worked in foreground, when I tried to swipe to home and send app to background and send a message, nothing is received. When I reopen the app, the data message is then received. If I send multiple data messages, only the last one is received after reopening the app.

This behaviour also exists when simply locking the iPhone

There are 2 major problems here:

1- Data messages are not being received in background/terminated states in release mode but works fine in profile mode

2- Even after re-opening the app, only the last data message is being received (similar to collapsing notifications in FCM)

I didn’t find any comments regarding this behaviour in FCM doumentation. Can someone look into this to ensure if this is a normal behaviour or not. If so, how can I overcome it or a work around ?

Data Message Sending Function:

public function sendDataMessage($deviceTokens, $data = [], $priority = "high")
{
    $messaging = app('firebase.messaging');
    $clean_data = $data;
    if (isset($data["type"]) && $data["type"] == "chat" && $data["action"] == "receiveMessage") {
        unset($clean_data["fcm_message"]);
    }
    $messages = [];
    foreach ($deviceTokens as $token) {
        try {
            if (isset($data["type"]) && $data["type"] == "chat" && $data["action"] == "receiveMessage") {
                $chat_message = $data["fcm_message"];
                $clean_data["title"] = Chats::select("name")->find($data["chat_id"])->name;
                $clean_data["body"] = $chat_message["sender"]["name"] . ": " . ($chat_message["content"]["type"] == "Text" ? $chat_message["content"]["body"] : $chat_message["content"]["type"]);
            }
            $messages[] = CloudMessage::withTarget('token', $token)
                ->withData($clean_data)
                ->withAndroidConfig(AndroidConfig::fromArray([
                    'priority' => 'high',  // Use high priority
                    'ttl' => 86400 * 28, // 4 weeks in seconds
                ]))
                ->withApnsConfig(ApnsConfig::fromArray([
                    'headers' => [
                        'apns-expiration' => strval(time() + 86400 * 28), // Expiry timestamp
                        'apns-priority' => '10',
                    ],
                    'payload' => [
                        'aps' => [
                            // 'sound' => 'default',
                            "content-available" => 1,
                            "mutable-content" => 1
                        ],
                    ],
                ]));
        } catch (Exception $e) {
            return $e;
        }
    }
    try {
        $report = $messaging->sendAll($messages);
    } catch (NotFound $e) {
        return $e;
    } catch (Exception $e) {
        return $e;
    }

    return $report->successes()->count();
}

Firebase Handler:

static void initializeFCMHandler() async {
    FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage);
    FirebaseMessaging.onMessage.listen(handleMessage);
}

@pragma('vm:entry-point')
static Future<void> handleBackgroundMessage(RemoteMessage? message) async {
    if (message?.notification != null) {
      handleNotification(message, isBackground: true);
    } else {
      handleDataMessage(message, isBackground: true);
    }
}

static void handleMessage(RemoteMessage? message) async {
    if (message?.notification != null) {
      handleNotification(message);
    } else {
      handleDataMessage(message);
    }
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Only-data messages being collapsed and dropped in iOS

I want to send multiple data messages to my flutter app. I was working with notifications as they were sent in all states (foreground, background, terminated) but found that they are being collapsed. I switched to use only-data messages and after some code modification, it works flawlessly on Android when the app is in any condition, I always receive the data message. Even if the user has no internet connection and multiple messages are sent, each one will be received after reconnecting. When testing this on iOS, I ran the app in release mode as I did in Android and everything worked in foreground, when I tried to swipe to home and send app to background and send a message, nothing is received. When I reopen the app, the data message is then received. If I send multiple data messages, only the last one is received after reopening the app.

This behaviour also exists when simply locking the iPhone

There are 2 major problems here:

1- Data messages are not being received in background/terminated states in release mode but works fine in profile mode

2- Even after re-opening the app, only the last data message is being received (similar to collapsing notifications in FCM)

I didn’t find any comments regarding this behaviour in FCM doumentation. Can someone look into this to ensure if this is a normal behaviour or not. If so, how can I overcome it or a work around ?

Data Message Sending Function:

public function sendDataMessage($deviceTokens, $data = [], $priority = "high")
{
    $messaging = app('firebase.messaging');
    $clean_data = $data;
    if (isset($data["type"]) && $data["type"] == "chat" && $data["action"] == "receiveMessage") {
        unset($clean_data["fcm_message"]);
    }
    $messages = [];
    foreach ($deviceTokens as $token) {
        try {
            if (isset($data["type"]) && $data["type"] == "chat" && $data["action"] == "receiveMessage") {
                $chat_message = $data["fcm_message"];
                $clean_data["title"] = Chats::select("name")->find($data["chat_id"])->name;
                $clean_data["body"] = $chat_message["sender"]["name"] . ": " . ($chat_message["content"]["type"] == "Text" ? $chat_message["content"]["body"] : $chat_message["content"]["type"]);
            }
            $messages[] = CloudMessage::withTarget('token', $token)
                ->withData($clean_data)
                ->withAndroidConfig(AndroidConfig::fromArray([
                    'priority' => 'high',  // Use high priority
                    'ttl' => 86400 * 28, // 4 weeks in seconds
                ]))
                ->withApnsConfig(ApnsConfig::fromArray([
                    'headers' => [
                        'apns-expiration' => strval(time() + 86400 * 28), // Expiry timestamp
                        'apns-priority' => '10',
                    ],
                    'payload' => [
                        'aps' => [
                            // 'sound' => 'default',
                            "content-available" => 1,
                            "mutable-content" => 1
                        ],
                    ],
                ]));
        } catch (Exception $e) {
            return $e;
        }
    }
    try {
        $report = $messaging->sendAll($messages);
    } catch (NotFound $e) {
        return $e;
    } catch (Exception $e) {
        return $e;
    }

    return $report->successes()->count();
}

Firebase Handler:

static void initializeFCMHandler() async {
    FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage);
    FirebaseMessaging.onMessage.listen(handleMessage);
}

@pragma('vm:entry-point')
static Future<void> handleBackgroundMessage(RemoteMessage? message) async {
    if (message?.notification != null) {
      handleNotification(message, isBackground: true);
    } else {
      handleDataMessage(message, isBackground: true);
    }
}

static void handleMessage(RemoteMessage? message) async {
    if (message?.notification != null) {
      handleNotification(message);
    } else {
      handleDataMessage(message);
    }
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật