flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🚀 [firebase_messaging] allow to switch firebase project at runtime.

Open GChanathip opened this issue 6 months ago • 1 comments

What feature would you like to see?

Expose the instaceFor method for public to allow user to switch firebase project at runtime.

Image

I'm not sure what is the reason that why Messaging does not support multiple Firebase Apps. while FirebaseMessagingPlatform alreadly expose this?

Image

GChanathip avatar Jul 19 '25 09:07 GChanathip

i just found the related issue https://github.com/firebase/flutterfire/issues/12428 seem like it about platfrom constraint? but i have seen some native implementation to achieve this by initialize multi FirebaseApp at launch and then choose firebaseApp by name later.

Android

                val firebaseMessaging = FirebaseApp.getInstance("appName")
                    .get(FirebaseMessaging::class.java) as FirebaseMessaging
                firebaseMessaging.token.addOnFailureListener {
                    result.error(it.toString(), it.message, "")
                }.addOnCompleteListener {
                    println("FCM Token -> ${it.result}")
                    result.success(it.result)
                }

and this for iOS

    let fbsenderID = FirebaseApp.app(name: "appName")?.options.gcmSenderID ?? ""
    Messaging.messaging().retrieveFCMToken(forSenderID: fbsenderID, completion: { fcmToken, error in
        tokenReturn(fcmToken, error)
    })

GChanathip avatar Jul 19 '25 10:07 GChanathip