Skip to content

Commit 2f459ec

Browse files
committed
Set iOS delegates as part of blocking initialization
Placing this init code in a `launch` makes it run asynchronously on app start, which means it can happen after the app was already initialized and received some notification related events (specifically, `userNotificationCenter didReceive response`)
1 parent 943b8aa commit 2f459ec

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

kmpnotifier/src/iosMain/kotlin/com/mmk/kmpnotifier/firebase/FirebasePushNotifierImpl.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@ internal class FirebasePushNotifierImpl : PushNotifier {
2323
private val firebaseMessageDelegate by lazy { FirebaseMessageDelegate() }
2424

2525
init {
26-
MainScope().launch {
27-
currentLogger.log("FirebasePushNotifier is initialized")
28-
UNUserNotificationCenter.currentNotificationCenter().delegate =
29-
IosNotifier.NotificationDelegate()
30-
FIRMessaging.messaging().delegate = firebaseMessageDelegate
31-
UIApplication.sharedApplication.registerForRemoteNotifications()
32-
}
33-
26+
currentLogger.log("FirebasePushNotifier is initializing")
27+
UNUserNotificationCenter.currentNotificationCenter().delegate =
28+
IosNotifier.NotificationDelegate()
29+
FIRMessaging.messaging().delegate = firebaseMessageDelegate
30+
UIApplication.sharedApplication.registerForRemoteNotifications()
31+
currentLogger.log("FirebasePushNotifier is initialized")
3432
}
3533

36-
3734
override suspend fun getToken(): String? = suspendCoroutine { cont ->
3835
FIRMessaging.messaging().tokenWithCompletion { token, error ->
3936
cont.resume(token)

0 commit comments

Comments
 (0)