canOpenURL Is Deprecated: What to Call Instead
Apple retired a method that has shipped since iOS 3.0 in three sentences: “canOpenURL: is deprecated. Attempt to open the URL and handle any failure instead of validating it first. Using universal links instead of custom URL schemes removes the need for this validation entirely.”1
The entry carries radar 179874781 and sits under UIKit, Deprecations, directly beneath the scene life cycle mandate that stops apps from launching.1 The neighboring entry names a consequence. The canOpenURL entry names none.
Each of the three sentences is a separate instruction, and only the second answers the question a developer actually has: what do I write instead? Apple’s answer changes the shape of the call, not just the name.
TL;DR
- Apple deprecated
canOpenURL(_:)at 27.0 on iOS, iPadOS, Mac Catalyst, tvOS, and visionOS, with the message “Prefer attempting to open URLs and handling any failures.”2 No removal version, no runtime consequence. - The change with teeth is a number, and it sits in the deprecated method’s own discussion rather than in any release note: “Apps linked on or after iOS 27 are limited to a maximum of 25 entries in the
LSApplicationQueriesSchemeskey,” down from 50.2 The trigger is the SDK you link against. - The mechanical swap is
open(_:options:completionHandler:)and its Boolean, which needs no allowlist entry: “theopen(_:options:completionHandler:)method isn’t constrained by theLSApplicationQueriesSchemesrequirement.”2 - One pattern loses its replacement, because
canOpenURLanswers before you draw anything while attempting answers by consequence: a success puts another app in the foreground.2 What survives isuniversalLinksOnly, anopenoption since iOS 10 that Apple has not deprecated: it “opens the URL only if the URL is a valid universal link and there is an installed app capable of opening that URL.”3 - SwiftUI never shipped the method, and its completion Boolean already means “can open” rather than “did open.”415 Across seven of my shipping apps and 463…
评论
?
参与讨论