the url is in the form scheme://someAction
At risk of oversimplifying it, the scheme is typically the name of your app. this is how you confirm that the url is intended for your app
in your widget body you use the widgetURL modifier:
var body: some View {
content().widgetURL("myApp://someAction")
}
then in your app you use the onOpenURL modifier to pick up the url, check its for your app and parse it to determine what to do. someAction is the message you are sending the app to tell it what to do
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
guard url.scheme == "myApp" else { return }
print(url) // parse the url to get someAction to determine what the app needs do
}
}
}
I usually make the url of the form myApp://someAction/parms so that I can parse the url to determine what the app needs to do and also pass it some parms. Some people like to do this by forming the URL properly with URLComponents - path, queryItems etc. this is probably best practice.