swiftwatchkitapple-watchwatchos

How can I open URLs in watchOS?


Can a standalone Apple Watch app open a URL like we can in iOS:

UIApplication.sharedApplication().openURL(url!)

I want to display a message about an update when a new app is published. I want the user to go the URL for the update. Is there any good way?


Solution

  • I don't know if you're using SwiftUI or not, but the Link View is shown in the Documentation as available for watchOS. However using it in practice only prompts the user to open the link on their iPhone. As a standalone app since Safari is not available on watchOS you might want to consider other options to alert your user of an update.

    struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, World!")
            Link("Apple.com", destination: URL(string: "https://www.apple.com")!)
        }
    }
    }
    

    Apple Watch