JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.92k stars 1.16k forks source link

iOS Crash: LocalUriHandler not handling phone URIs #3971

Open yuroyami opened 9 months ago

yuroyami commented 9 months ago

(@mazunin-v-jb : moved versions here) Kotlin version: 1.9.21 Compose-jb: 1.5.11 OS: iOS 16.3.1 arm64

Consider the following code:

val websiteUri = "https://www.example.com"
val phoneUri = "tel:+29429402"

val uriHandler = LocalUriHandler.current
uriHandler.openUri(websiteUri) //Works fine on Android and iOS
uriHandler.openUri(phoneUri) <--- Crashes

The syntax tel: + phone number is used for Android only (afaik), however, it is not working on iOS. I haven't tested yet whether the iOS syntax (tel:// + phone number) is handled on iOS (probably cannot be handled on Android if it works on iOS). The LocalUriHandler needs to route both syntaxes to their proper handlers on each platform, replacing tel: with tel:// for iOS, and removing the two slashes if it is being routed to Android from tel:// syntax.

In order to launch a telephony URI for iOS, I use this code for now:

        if let phoneURL = URL(string: "tel://\(phoneNumber)") {
            UIApplication.shared.open(phoneURL, options: [:], completionHandler: nil)
        }
mazunin-v-jb commented 9 months ago

Hello, thank you for submitting the issue. Could you please also provide the log crash?

mazunin-v-jb commented 9 months ago

@yuroyami I tried to reproduce it on 1.5.11 Compose (1.9.21 Kotlin) on the clean project made from that template and it worked as expected. Could you please also provide the reproducible example and the following information? Versions

yuroyami commented 8 months ago

@mazunin-v-jb I am away from my work station for quite some while but as far as I remember, the issue occurred while I was using a phone number that contains white spaces and parentheses. I did not try using a phone number without white spaces or the parentheses.

Kotlin version: 1.9.21 Compose-jb: 1.5.11 OS: iOS 16.3.1 arm64

mazunin-v-jb commented 8 months ago

Thank you for your answer. As far as I remember, I've tried just a number without any special symbols like you described. I'll take a look.

mazunin-v-jb commented 6 months ago

Hello, @yuroyami! Sorry for long responding. I've tried to dig dipper into this problem, so I've created a reproducer with many cases of phone numbers. Could you please check it? For me, it works as expected on both iOS and Android.

Also, for iOS testing, please use a physical device (iPhone or iPad). iOS Simulator can't forward tel:/ uri to phone app cause it doesn't have it. Maybe that was the reason for different behavior in our cases.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.