firebase / firebase-admin-java

Firebase Admin Java SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
538 stars 263 forks source link

Data/notification messages delay or not received on iOS devices #1004

Open SalvadorCali opened 4 hours ago

SalvadorCali commented 4 hours ago

Library version: 9.2.0 Firebase Product: Cloud Messaging (FCM)

Hi! We are using the version 9.2.0 of the library to send data messages to both Android and iOS devices. On Android, the messages are received instantly as expected, but on iOS devices, there is a noticeable delay (1+ hours), or sometimes the messages are not received at all.

I would like to understand if there is any known issue with FCM data/notification messages on iOS or if there's a recommended approach to ensure reliable and timely message delivery on iOS devices.

This is a snippet of my code:


val notificationsTtlInSeconds = 300
val title = news.title
val subtitle = news.subtitle
val body = news.body

val androidTTL = notificationsTtlInSeconds.toLong() * 1000
val androidConfig = AndroidConfig.builder()
    .setNotification(
        AndroidNotification.builder()
            .setTitle(title)
            .setBody(body)
            .setIcon("stock_ticker_update")
            .setClickAction("ON_MESSAGE_RECEIVED")
            .setSound("default")
            .build()
    )
    .setPriority(HIGH)
    .setTtl(androidTTL)
    .build()

val iosTTL = Instant.now().plus(Duration.ofSeconds(notificationsTtlInSeconds.toLong())).epochSecond
val iosConfig = ApnsConfig.builder()
    .putHeader("apns-priority", "10")
    .putHeader("apns-expiration", "$iosTTL")
    .setAps(
        Aps.builder()
            .setAlert(
                ApsAlert.builder()
                    .setTitle(title)
                    .setSubtitle(subtitle)
                    .setBody(body)
                    .build()
            )
            .setSound("default")
            .setBadge(1)
            .build()
    )
    .build()

val conditionString = createConditionString(news)
val message = ObjectMapper().writeValueAsString(news)

val builder = Message.builder()
    .setAndroidConfig(androidConfig)
    .setApnsConfig(iosConfig)
    .putData("id_news", news.idNews)
    .putData("message", message)

FirebaseMessaging.getInstance().send(message)

We also tried notification messages instead of data messages and `apns-priority` 5, but the problem still persists.
google-oss-bot commented 4 hours ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.