---
title: "setURLSchemeHandler(_:forURLScheme:)"
framework: webkit
role: symbol
role_heading: Instance Method
path: "webkit/wkwebviewconfiguration/seturlschemehandler(_:forurlscheme:)"
---

# setURLSchemeHandler(_:forURLScheme:)

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

## Declaration

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

## Parameters

- `urlSchemeHandler`: The object to handle the URL scheme. This object must adopt the doc://com.apple.webkit/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 doc://com.apple.webkit/documentation/WebKit/WKWebView/handlesURLScheme(_:) class method of doc://com.apple.webkit/documentation/WebKit/WKWebView.

## Discussion

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.

## See Also

### Adding handlers for custom URL schemes

- [urlSchemeHandler(forURLScheme:)](webkit/wkwebviewconfiguration/urlschemehandler(forurlscheme:).md)
