What this thread does
Route notification links and explicitly pasted URLs through one URLComponents allowlist before navigating under the current account.
Do first: define one typed destination and one parser; call it from every link entry point before changing navigation state. The following is a deliberately narrow application policy for reader://thread?id=<UUID>, using Foundation's URLComponents properties.
import Foundation
enum Destination: Equatable {
case thread(UUID)
}
func destination(from raw: String) -> Destination? {
guard raw.utf8.count <= 2048,
let parts = URLComponents(string: raw),
parts.scheme?.lowercased() == "reader",
parts.host?.lowercased() == "thread",
parts.user == nil, parts.password == nil,
parts.port == nil, parts.path.isEmpty,
parts.fragment == nil,
let items = parts.queryItems, items.count == 1,
items[0].name == "id",
let value = items[0].value,
let id = UUID(uuidString: value)
else { return nil }
return .thread(id)
}
1. Connect incoming URLs. Feed url.absoluteString from SwiftUI's onOpenURL(perform:)) into this parser. Feed a notification's destination string into the same parser when handling the person's notification response. Keep the parser free of navigation, credential reads and network calls. The shared parser and size cap are design recommendations, rather than additional Foundation guarantees. 2. Reject ambiguity. This policy accepts exactly one id query item and no extra path, port, user information or fragment. Reject unknown destinations instead of opening an arbitrary URL. Treat parsed components as decoded data; do not apply a second percent-decoding pass. Foundation distinguishes decoded properties from their percent-encoded counterparts in its implementation and API comments. 3. Gate navigation on current access. Keep a parsed destination pending while signed out. After authentication, resolve the thread through the current account's authorized API; navigate only if access succeeds. Discard a pending destination on an account switch or repeat the access check for the new account. A URL is a destination hint; the account check is an application security requirement. The account-access and account-switch policies are design recommendations. 4. Expose an explicit Paste action. On iOS 16+, use UIPasteControl targeting a UIResponder that declares supported URL/text content through pasteConfiguration and implements paste(itemProviders:). Load a supported URL or string from the item provider, then pass that value through destination(from:). Handle unsupported content and load errors visibly. Kyle Lanchman's August 8, 2022 implementation report walks through the target, supported types and provider callback. 5. Finish on the UI actor. Recheck the selected account after asynchronous paste loading or destination lookup, before updating navigation. Offer an editable URL field with the standard Paste menu as a fallback. Keep the existing screen available when the input is invalid or access is denied.
Avoid reading UIPasteboard.general.string automatically when the app launches or becomes active. Apple's WWDC22 privacy session explains that iOS 16 confirms intent for cross-app pasteboard access; a visibly displayed and tapped UIKit paste control provides that intent. A custom button that reads the pasteboard is not the system paste control.
Keep notification permission separate
Keep notification delivery permission separate from destination handling once a person opens a link or pastes it. Do not make Paste depend on a notification-permission decision.
Checks to add
Use fixed fixtures for a valid UUID; missing, repeated or unknown query items; an extra path; unexpected scheme/host; a fragment; malformed input; and overlong input. For asynchronous entry points, include sign-out and account-switch cases between parsing and navigation. Exercise the actual Paste control with URL, plain text and unsupported clipboard content.
Evidence
- Apple, WWDC22, June 2022: What's new in privacy establishes the iOS 16 pasteboard intent model and UIKit paste controls.
- Kyle Lanchman, August 8, 2022: firsthand UIPasteControl walkthrough demonstrates the target/configuration/provider sequence. It supports the paste integration, not the combined notification-to-navigation design.
Limits
The parser is a proposed custom-scheme contract. Registering a scheme, setting up Universal Links, resolving a thread and maintaining navigation state require app-specific integration. No opt-in-rate, cross-app routing or universal-link delivery claim follows from the paste sources.
Not for: native iOS provisional-permission timing and denial recovery; see ios-notification-permission-timing-provisional-preprompt.
Started from a post by @Apple, packaged by the editor. Original post