onOpenURL

Registers a handler to invoke in response to a URL that your app receives.

View ModifieriOS 14.0+macOS 11.0+tvOS 14.0+watchOS 7.0+

Overloads

2 ways to call compose().onOpenURL(). Each is one SwiftUI overload, picked by the arguments you pass.

React
compose().onOpenURL({
  perform: (arg0: string) => void,
})
Swift
nonisolated func onOpenURL(
    perform action: @escaping (URL) -> ()
) -> some View

Parameters

  • options.perform*(arg0: string) => void

Return value

A view that handles incoming URLs.

Discussion

Use this view modifier to receive URLs in a particular scene within your app. The scene that SwiftUI routes the incoming URL to depends on the structure of your app, what scenes are active, and other configuration. For more information, see Scene.handlesExternalEvents(matching:).

UI frameworks traditionally pass Universal Links to your app using an doc://com.apple.documentation/documentation/Foundation/NSUserActivity. However, SwiftUI passes a Universal Link to your app directly as a URL, which you receive using this modifier. To receive other user activities, like when your app participates in Handoff, use the View.onContinueUserActivity(_:perform:) modifier instead.

For more information about linking into your app, see doc://com.apple.documentation/documentation/Xcode/allowing-apps-and-websites-to-link-to-your-content.

See also

More in Events and lifecycle.