Search code examples
androidiosswiftkotlinkotlin-multiplatform

KMM - Method to share result from KMM library to iOS and Android app


I have developed a KMM library to interact between native apps written in Swift or Kotlin and a POS terminal. This library works well but we need to have a way to intercept logs to give assistance to customers. There is a way to share the logs from KMM library to Swift?

If this library had been in Swift developed I can use protocol/delegate or notification, there's a way to do the same in KMM?

Right now I used Napier to see logs in console, indeed, when I run the app with this library in Xcode the logs appear in Console. In native app we use a way to get logs from customers and analysing them, so we need to find a way to get some information from KMM library to native app

Thank you


Solution

  • If I understood your question correctly, then the below answer should help!

    Getting information from library to app would be done the same way as normal interface driven approach. Define an interface on KMP library, implement it on Swift, pass the reference to library and then use the reference to log whatever you need to pass back to the app.

    For example, here in KaMPKit project, there is koin related method fun initKoinIos() on the library side.

    The swift app calls this method from app.

    Same you way you implement an interface on Swift side and pass it to library.