Skip to content

How to open URL in android? #173

Answered by marcprux
Arnav-arw asked this question in Q&A
Discussion options

You must be logged in to vote

If you are in a SwiftUI view, the recommended way to open a URL is like:

public struct ContentView: View {
    @Environment(\.openURL) var openURLAction

    public var body: some View {
        Button("Launch URL") {
            let url = URL(string: "https://skip.tools")!
            openURLAction(url)
        }
    }
}

If you need to call this from a non-SwiftUI view (e.g., from model code), note that we do implement UIApplication.shared.open, but there was a bug with it that prevented it from working until the latest version of SkipUI (0.10.7). So once you update your packages, this should also work:

func openSkipURL() {
    Task {
        let url = URL(string: "https://skip.tools")!
…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Arnav-arw
Comment options

Answer selected by marcprux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants