I want to use Kotlin native to make my own cross-platform framework for iOS/Android app
I created a project from the multi-platform tutorial
I just see how Android and Swift can call Kotlin code
but I have no idea to make a message channel when Kotlin want to ask Swift to do something
and I want to make the same thing in Android too
Hello @nkheart, I hope this can help you.
If you make the expect and actual class below the common package and iOS/Android package respectively. You can use swift libraries through kotlin code.
There is an example below.
Common
expect class Location()
expect fun Location.getLocationPermission(): Boolean
iOS
actual fun Location.getLocationPermission(): Boolean {
return CLLocationManager.locationServicesEnabled() && CLLocationManager.authorizationStatus() == kCLAuthorizationStatusAuthorizedWhenInUse
}
After that you can use the expect “interface” on you kotlin code, and the call will be able to make the iOS or Android implementation.