Contents

setURLSchemeHandler(_:forURLScheme:)

Registers an object to load resources associated with the specified URL scheme.

Declaration

func setURLSchemeHandler(_ urlSchemeHandler: (any WKURLSchemeHandler)?, forURLScheme urlScheme: String)

Parameters

  • urlSchemeHandler:

    The object to handle the URL scheme. This object must adopt the Wkurlschemehandler protocol.

  • urlScheme:

    The URL scheme to handle. Scheme names are case sensitive, must start with an ASCII letter, and may contain only ASCII letters, numbers, the “+” character, the “-” character, and the “.” character. This method raises an Invalidargumentexception if the scheme name is an empty string or contains any other characters.

    It is a programmer error to register a handler for a scheme WebKit already handles, such as https, and this method raises an Invalidargumentexception if you try to do so. To determine whether WebKit handles a specific scheme, call the Handlesurlscheme(_:) class method of Wkwebview.

Discussion

Use this method to register any custom resource types that your web content uses. For example, you might register a custom URL scheme for resources that you provide programmatically from your app.

It is a programmer error to call this method more than once for the same scheme.

See Also

Adding handlers for custom URL schemes