Agent skills for iOS, iPadOS, Swift, SwiftUI, and modern Apple framework development.
71
89%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Advisory
Suggest reviewing before use
Use URLSchemeHandler when the app owns the content source and needs WebKit to resolve resources under a custom scheme.
Good fits:
Do not use custom schemes for ordinary server-hosted pages that should just load over HTTPS.
import Foundation
import WebKit
@MainActor
func makeDocsPage() -> WebPage {
var configuration = WebPage.Configuration()
configuration.urlSchemeHandlers[URLScheme("docs")!] = DocsSchemeHandler(bundle: .main)
return WebPage(configuration: configuration)
}If WebKit already owns a scheme, URLScheme("https") style registration does not work. Use a genuinely custom scheme.
A handler replies with an async sequence of intermixed response and data values.
struct DocsSchemeHandler: URLSchemeHandler {
let bundle: Bundle
func reply(for request: URLRequest) -> some AsyncSequence<URLSchemeTaskResult> {
AsyncStream { continuation in
guard let url = request.url,
let fileURL = bundle.url(forResource: url.host, withExtension: "html", subdirectory: "Docs")
else {
continuation.finish()
return
}
do {
let data = try Data(contentsOf: fileURL)
let response = URLResponse(
url: url,
mimeType: "text/html",
expectedContentLength: data.count,
textEncodingName: "utf-8"
)
continuation.yield(.response(response))
continuation.yield(.data(data))
continuation.finish()
} catch {
continuation.finish()
}
}
}
}Keep MIME type and encoding aligned with the actual content you serve.
Once registered, load the custom URL like any other page.
let page = makeDocsPage()
for try await _ in page.load(URL(string: "docs://welcome")!) {
}This works well when the HTML references other assets with the same custom scheme.
If WebKit no longer needs the resource, it cancels the task producing the async sequence. Treat cancellation as normal behavior when:
Do not build logic that assumes every scheme-handled request runs to completion.
skills
accessorysetupkit
references
activitykit
references
adattributionkit
references
alarmkit
references
app-clips
app-intents
references
app-store-optimization
app-store-review
apple-on-device-ai
appmigrationkit
references
audioaccessorykit
references
authentication
references
avkit
references
background-processing
references
browserenginekit
references
callkit
references
carplay
references
cloudkit
references
contacts-framework
references
core-bluetooth
references
core-data
core-motion
references
core-nfc
references
coreml
references
cryptokit
references
cryptotokenkit
references
debugging-instruments
device-integrity
references
dockkit
references
energykit
references
eventkit
references
financekit
references
focus-engine
gamekit
references
healthkit
references
homekit
references
ios-accessibility
ios-localization
ios-networking
ios-simulator
references
mapkit
metrickit
references
musickit
references
natural-language
references
paperkit
references
passkit
references
pdfkit
references
pencilkit
references
permissionkit
references
photokit
push-notifications
realitykit
references
relevancekit
references
scenekit
references
sensorkit
references
speech-recognition
spritekit
references
storekit
swift-api-design-guidelines
swift-architecture
swift-charts
references
swift-codable
swift-concurrency
swift-formatstyle
swift-language
swift-security
references
swift-testing
swiftdata
swiftlint
swiftui-animation
swiftui-gestures
references
swiftui-layout-components
swiftui-liquid-glass
references
swiftui-patterns
swiftui-performance
swiftui-uikit-interop
swiftui-webkit
tabletopkit
references
tipkit
references
vision-framework
weatherkit
references
widgetkit
references