mirzemehdi / KMPNotifier

Kotlin Multiplatform Push Notification Library targetting android, iOS, Desktop and Web (JS and Wasm)
http://mirzemehdi.com/KMPNotifier/
Apache License 2.0
321 stars 18 forks source link

On iOS method registerForRemoteNotification is called multiple times #66

Closed coletz closed 1 month ago

coletz commented 2 months ago

Right now the method registerForRemoteNotifications is called every time the FirebasePushNotifierImpl is instantiated, as seen here: https://github.com/mirzemehdi/KMPNotifier/blob/29def58f7c60a06a1b13f7f1a01dd9058c1462ae/kmpnotifier/src/iosMain/kotlin/com/mmk/kmpnotifier/firebase/FirebasePushNotifierImpl.kt#L26

PushNotifier is bound using the factory method: https://github.com/mirzemehdi/KMPNotifier/blob/29def58f7c60a06a1b13f7f1a01dd9058c1462ae/kmpnotifier/src/iosMain/kotlin/com/mmk/kmpnotifier/di/PlatformModule.ios.kt#L28

This way, every time one tries to use getPushNotifier() a new instance is created from koin: https://github.com/mirzemehdi/KMPNotifier/blob/29def58f7c60a06a1b13f7f1a01dd9058c1462ae/kmpnotifier/src/commonMain/kotlin/com/mmk/kmpnotifier/notification/NotifierManagerImpl.kt#L23

I am not sure if this is causing any issue, but maybe exposing a "register" method called from the user would be better? Maybe even adding a flag (to NotificationPlatformConfigurationIos) for automatically calling this "register" method in inside the initialize method?

mirzemehdi commented 1 month ago

@coletz I think there is no point of exposing register method. What would be usecase for that?. What I can do though instead of factory making it singleton, but still what would be issue if it is instantiated each time?

mirzemehdi commented 1 month ago

Closing this issue due to inactivity. If this is still an issue or need a help, please feel free to reopen the issue and provide additional context or updates. Thank you.