# SwiftUI Custom URL Schemes

DevFeed: [SwiftUI Custom URL Schemes](<https://devfeed.tech/articles/swiftui-custom-url-schemes-21088.md>)

Original publisher: [Read original article](<https://useyourloaf.com/blog/swiftui-custom-url-schemes/>)

Author: Keith Harrison

Published: 2025-10-27T11:26:47Z

Content type: tutorial

Language: en

Sources: [K. Harrison](<https://devfeed.tech/sources/k-harrison.md>)

Topics: [SwiftUI](<https://devfeed.tech/topics/swiftui.md>), [WebView](<https://devfeed.tech/topics/webview.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [WebKit](<https://devfeed.tech/topics/webkit.md>), [App](<https://devfeed.tech/topics/app.md>)

Tags: [async](<https://devfeed.tech/tags/async.md>), [auto-layout](<https://devfeed.tech/tags/auto-layout.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [ios](<https://devfeed.tech/tags/ios.md>), [ios-26](<https://devfeed.tech/tags/ios-26.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>), [protocol](<https://devfeed.tech/tags/protocol.md>), [scheme](<https://devfeed.tech/tags/scheme.md>), [swift](<https://devfeed.tech/tags/swift.md>), [swiftui](<https://devfeed.tech/tags/swiftui.md>), [web](<https://devfeed.tech/tags/web.md>), [webview](<https://devfeed.tech/tags/webview.md>), [wwdc](<https://devfeed.tech/tags/wwdc.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

## AI overview

This tutorial explains how to create a custom URL scheme handler for SwiftUI WebViews in iOS 26. It covers implementing URLSchemeHandler, loading local HTML resources from an app bundle, registering the handler in a WebPage configuration, and displaying the page in a WebView.

## Source excerpt

Create a custom URL scheme handler for SwiftUI WebViews. Custom URL schemes Apple introduced both WebView and WebPage SwiftUI views in iOS 26. These provide similar WebKit functionality to the UIKit WKWebView APIs. This includes being able to register custom URL schemes to load local resources. Suppose I have an App that loads quotations from the local App bundle. My URL scheme uses the format: quotes://001.html There are a few steps to support a custom URL scheme: Create a custom URL scheme handler that knows how to load the local resources. Register the scheme handler in a WebPage configuration. Have the WebView load and display the web page. Let's look at each of those steps. URLSchemeHandler (iOS 26) The URLSchemeHandler is a protocol with a reply method to return an async sequence of results. The AsyncSequence expects us to either yield a URLResponse and some data or throw an error. struct QuoteSchemeHandler: URLSchemeHandler { static let scheme = "quotes" func reply(for request: URLRequest) -> some AsyncSequence< URLSchemeTaskResult, any Error > { AsyncThrowingStream { continuation in ... } } } The reply method provides us with the URLRequest. I start by extracting the URL and checking it matches our quotes scheme: guard let url = request.url else { continuation.finish(throwing: QuoteError.missingURL) return } guard url.scheme == QuoteSchemeHandler.scheme else { continuation.finish(throwing: QuoteError.invalidScheme) return } To construct the URL response I need the mime type and length of the data. I first extract the filename from the URL, determine the mime type from the file extension, and then load the data: do { let file = try filename(for: url) let mimeType = try mimeType(for: file) let data = try Data(contentsOf: file) I can then build the URLResponse: let response = URLResponse( url: url, mimeType: mimeType, expectedContentLength: data.count, textEncodingName: "utf-8" ) If nothing has gone wrong I then add the response and the data to the AsyncSequenc