mirzemehdi / KMPNotifier

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

Can't access NotifierManager in iOS in Compose Multiplatform #68

Open Soabbar opened 1 week ago

Soabbar commented 1 week ago

Hi @mirzemehdi KMPNotifier and Kotlin version: kmpnotifier version: 1.2.1, kotlin version: 2.0.0

Describe the bug Setting up the library in Android seems to be working fine but it is not on iOS.

error: cannot find 'NotifierManager' in scope
      NotifierManager.initialize(configuration: NotificationPlatformConfigurationIos(showPushNotification: true))

error: cannot find 'NotificationPlatformConfigurationIos' in scope
      NotifierManager.initialize(configuration: NotificationPlatformConfigurationIos(showPushNotification: true))

The following build commands failed:
    SwiftCompile normal arm64 Compiling\ iOSApp.swift

In which platform bug occurs? ios

To Reproduce I followed the README but I am a bit confused about the Import shared I am using the Compose Multiplatform from Jetbrains, is that compatible?

listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->

        iosTarget.binaries.framework {
            export("io.github.mirzemehdi:kmpnotifier:1.2.1")
            baseName = "ComposeApp"
            isStatic = true
        }
    }

commonMain.dependencies {
            api("io.github.mirzemehdi:kmpnotifier:1.2.1")
}
import SwiftUI
import FirebaseCore
import FirebaseMessaging

class AppDelegate: NSObject, UIApplicationDelegate {

  func application(_ application: UIApplication,
                   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

      FirebaseApp.configure() //important

      //By default showPushNotification value is true.
      //When set showPushNotification to false foreground push  notification will not be shown.
      //You can still get notification content using #onPushNotification listener method.

      NotifierManager.initialize(configuration: NotificationPlatformConfigurationIos(showPushNotification: true))

    return true
  }

  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
  }

}

@main
struct iOSApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
mirzemehdi commented 1 week ago

@Soabbar you missed import ComposeApp in ios part instead of import shared. This name comes from baseName that is defined in gradle file:


iosTarget.binaries.framework {
    export("io.github.mirzemehdi:kmpnotifier:1.2.1")
    baseName = "ComposeApp" <--- this one
    isStatic = true
}