<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKWebViewConfiguration/setURLSchemeHandler(_:forURLScheme:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKWebViewConfiguration(im)setURLSchemeHandler:forURLScheme:"
  },
  "title" : "setURLSchemeHandler(_:forURLScheme:)"
}
-->

# setURLSchemeHandler(_:forURLScheme:)

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

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

## Parameters

`urlSchemeHandler`

The object to handle the URL scheme. This object must adopt the [`WKURLSchemeHandler`](/documentation/WebKit/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 <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/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     <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException>     if you try to do so. To determine whether WebKit handles a specific scheme, call the [`handlesURLScheme(_:)`](/documentation/WebKit/WKWebView/handlesURLScheme(_:))     class method of [`WKWebView`](/documentation/WebKit/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.

> Tip:
> To prevent future conflicts with WebKit, include the name of your app or company in any custom scheme names.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)