https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Aleksandr Davliatov

12/09/2023, 7:03 PM
Hey! how can I open a URL link in KMM?
r

Raed Ghazal

12/09/2023, 7:05 PM
you have to create an implementation for each platform, if Android and iOS androidMain
Copy code
val browserIntent = Intent(
    Intent.ACTION_VIEW,
    Uri.parse(url)
)
context.startActivity(browserIntent)
iosMain
Copy code
import platform.Foundation.NSURL
import platform.UIKit.UIApplication

val url = NSURL.URLWithString(it)
UIApplication.sharedApplication().openURL(url)
❤️ 1
a

Aleksandr Davliatov

12/09/2023, 7:06 PM
Thank you, @Raed Ghazal!
kodee welcoming 1
a

Anders Carlsen

12/09/2023, 11:00 PM
I thin this should work on iOS also (works on Android/Jvm):
Copy code
val uriHandler = LocalUriHandler.current
uriHandler.openUri(websiteUri)
5
♥️ 4
b

brandonmcansh

12/10/2023, 12:20 AM
It does
r

Raed Ghazal

12/10/2023, 2:27 PM
oh wow thanks for sharing @Anders Carlsen!
23 Views