KMPNotifier icon indicating copy to clipboard operation
KMPNotifier copied to clipboard

onNewToken is not called on iOS Side sometimes

Open mirzemehdi opened this issue 2 years ago • 3 comments

mirzemehdi avatar Dec 02 '23 16:12 mirzemehdi

Can't reproduce why this happens. But if this occurs as a workaround for now, you can call val firebasePushToken = NotifierManager.getPushNotifier().getToken() in coroutine scope, and this will trigger onNewToken

mirzemehdi avatar Dec 02 '23 16:12 mirzemehdi

I've never received onNewToken on iOS, even after fresh install, but I assume that it could be Firebase configuration problem - like connecting Firebase with APNS certificate

Sabriel1984 avatar Mar 14 '24 10:03 Sabriel1984

If you tried above workaround solution, maybe you didn't enable Push Notifications in XCode

mirzemehdi avatar Mar 15 '24 01:03 mirzemehdi

This happens because of bad understanding of iOS garbage collection.

internal class FirebasePushNotifierImpl : PushNotifier {

    init {
        MainScope().launch {
            println("FirebasePushNotifier is initialized")
            UIApplication.sharedApplication.registerForRemoteNotifications()
            FIRMessaging.messaging().delegate = FirebaseMessageDelegate()
        }

    }
..
}

The FIRMessaging.messaging().delegate is a WEAK reference, all iOS sdk delegates are weak reference by design. So the FirebaseMessageDelegate() instance is garbage collected at any moment after it is set. I am actually surprised that it works at all. Just add strong reference to it, aka private val firMessageDelegate = FirebaseMessageDelegate() as a member of the class.

KoTius avatar Jul 16 '24 17:07 KoTius

@KoTius Thank you very much for this info, will check it

mirzemehdi avatar Jul 18 '24 22:07 mirzemehdi

This should be fixed in 1.2.0-alpha02 version

mirzemehdi avatar Aug 06 '24 01:08 mirzemehdi