What is a good way to open a web url in an externa...
# compose-ios
p
What is a good way to open a web url in an external browser for iOS with compose multiplatform? Tried `UIApplication.sharedApplication.openURL(NSURL(string = url))`but it prints
Copy code
[Application] BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(_:) needs to migrate to the non-deprecated UIApplication.open(_:options:completionHandler:). Force returning false (NO).
Also got the same result from
LocalUrlHandler.current.openUri(url)
. I tried what's written in the error message, but that function doesn't seem to be defined. Or I don't know how to write it - I come from an Android compose background.. I also tried directly adding the 1.7.2 version of androidx.compose.ui but gradle sync barfed - looks like a version conflict..
Oh. The error message is wrong too. I had to call a different overload of the same method name like this:
Copy code
UIApplication.sharedApplication.openURL(NSURL(string = url), options = mapOf<Any?, Any?>()) {
    if (!it) {
      println("Failed to open URL: $url")
    }
  }
Too bad the LocalUriHandler way is broken. The bug was reported but closed as a duplicate of the other different bug. https://youtrack.jetbrains.com/issue/CMP-6731
m
have you tried what the error suggests and using
UIApplication.shared.open(url, options: [:], completionHandler: nil)
rather than
openURL
?
m
Why do you think the other bug is different from yours? To me they look indeed identical.
m
I had this problem last week. While this bug is not solved, I decided to use this library for a while in my project https://github.com/final-class/WebView-Multiplatform-Mobile
p
LocalUrlHandler.current.openUri(url).
is calling the deprecated signature of openURL. But the bug linked as a duplicate is that the deprecated version no longer works.- which is not even a bug.
UIApplication.shared.open
doesn't exist in compose multiplatform. (Or I don't know how to make the reference resolve.)
m
👍 3
747 Views