0

When I start the iOS app, I want to send parameters from Firebase to my KMP project.

I put annotations in the KMP Kotlin class so that it would be visible, the bridge class that is generated in Objective-C has the parameters but they are inaccessible.

The ComposeApp class is generated automatically.

Here are the codes and project link.

https://github.com/flipnovidade/integration_call_apps_nativos_app_kmp

import SwiftUI
import FirebaseCore
import ComposeApp

@main
struct iOSApp: App {

    init() {
        FirebaseApp.configure()
        
        let swiftFirebaseRemoteConfig = SwiftFirebaseRemoteConfig()
        KoinInitKt.someFunctionThatNeedsSwift(isVercade: true) //Works
        
        KoinInitKt.someFunctionThatNeedsSwiftToRead(firebaseRemoteconfig: swiftFirebaseRemoteConfig) 
//error Type 'KoinInitKt' has no member 'someFunctionThatNeedsSwiftToRead'
        
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }

}

Swift class for my kmp project

@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
@OptIn(ExperimentalObjCName::class, BetaInteropApi::class)
@ObjCName(name = "KoinInit", exact = true)
@ExportObjCClass
actual class KoinInit(@ObjCName("delegate") delegate: SwiftFirebaseRemoteConfig) {

    init {
        doInitKoin(delegate = delegate)
    }

    fun initKoin(delegate: SwiftFirebaseRemoteConfig) {
        startKoin {
            modules(modules = moduleIos(delegate))
        }
    }

    fun doInitKoin(delegate: SwiftFirebaseRemoteConfig) = initKoin(delegate)

}

fun someFunctionThatNeedsSwift(isVercade: Boolean) {
    KmpLogger.d("someFunctionThatNeedsSwift", "receiver delegate $isVercade")
}

fun someFunctionThatNeedsSwiftToRead(firebaseRemoteconfig: SwiftFirebaseRemoteConfig) {
    KmpLogger.d("someFunctionThatNeedsSwift", "receiver delegate amem")
    val swiftFirebaseRemoteConfig: SwiftFirebaseRemoteConfig = (firebaseRemoteconfig)
    KoinInit(delegate = swiftFirebaseRemoteConfig)
}

composeApp .h auto generate

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("KoinInitKt")))
@interface ComposeAppKoinInitKt : ComposeAppBase
+ (void)someFunctionThatNeedsSwiftIsVercade:(BOOL)isVercade __attribute__((swift_name("someFunctionThatNeedsSwift(isVercade:)")));
+ (void)someFunctionThatNeedsSwiftToReadFirebaseRemoteconfig:(SwiftFirebaseRemoteConfig *)firebaseRemoteconfig __attribute__((swift_name("someFunctionThatNeedsSwiftToRead(firebaseRemoteconfig:)")));
@end

classes interpoleds for visible to kmp (use .d file in kmp) import FirebaseRemoteConfig import ComposeApp

@objc public class SwiftFirebaseRemoteConfig: NSObject, FirebaseRemoteConfigs {
    let remoteConfig = RemoteConfig.remoteConfig()
    
    @objc public func fetchAndActivateFirebaseRemoteConfigs(fetchIntervalInSeconds: Double) {
        remoteConfig.configSettings.minimumFetchInterval = fetchIntervalInSeconds
        remoteConfig.fetchAndActivate()
    }
    
    @objc public func getRemoteConfigString(key: String) -> String? {
        return remoteConfig.configValue(forKey: key).stringValue as String?
    }
    
}




#import <Foundation/Foundation.h>
#import <ComposeApp/ComposeApp.h>

@interface SwiftFirebaseRemoteConfig : NSObject <ComposeApp.FirebaseRemoteConfigs>

- (void)fetchAndActivateFirebaseRemoteConfigsWithFetchIntervalInSeconds:(double)fetchIntervalInSeconds;
- (NSString * _Nullable)getRemoteConfigStringWithKey:(NSString * _Nonnull)key;

@end
2
  • 1
    After much trying, I changed the format and succeeded. I gave up on interpolating from Swift to Kotlin using Objective-C Header, I did it via interface. Check out git for the solution. Commented Jul 4 at 18:51
  • solution: github.com/RhoBus/kmm-interoperability-example Commented Jul 4 at 18:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.