I’ve got several AppIntents that use iOS 17 specific features and are therefore annotated with @available(iOS 17.0, *)
. The AppIntent is correctly only listed on iOS 17 in the Shortcuts app and hidden on iOS 16. However, if I reference those AppIntents in an App Shortcut, the AppShortCut also appears on iOS 16, even though the AppIntent is iOS 17 only and even the AppShortcutsProvider is annotated with @available(iOS 17.0, *)
. When the user taps the App Shortcut on iOS 16, it leads to a crash of the application.
Example Code:
@available(iOS 17.0, *)
struct HelloIntent:AppIntent
{
static let title: LocalizedStringResource = "iOS 17 only AppIntent"
static var isDiscoverable: Bool = true
@Parameter(title:"Input")
var input:String
@MainActor
func perform() async throws -> some IntentResult {
return .result()
}
}
@available(iOS 17.0, *)
struct PhotoSyncShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
return [
AppShortcut(
intent: HelloIntent(),
phrases: ["(.applicationName) Hello"],
shortTitle: "Hello iOS 17",
systemImageName: "01.circle"
)
]
}
}
I would appreciate any hint on how to create the AppShortcuts without crashing on iOS 16.
2
Answers
I have tried to check your example code with a sample app whose minimum deployment target is
iOS 16.0
in Xcode(15.3).I haven’t faced any crash issues with the provided simple code.
And those
Appintents
with@available(iOS 17.0, *)
are not visible in theiOS 16.0
shortcut list.So my guess is your Old AppIntent somehow is using the
iOS 17.0
introduced feature. This can be achieved as follows-HelloIntent
in iOS 16.0 which AppIntent isHelloIntent
.HelloIntent
tag@available(iOS 17.0, *)
and use some iOS 17.0 features. (example-ParameterDependency
). And build the project.HelloIntent
shortcut.HelloIntent
shortcut crash.Because the already created shortcut won’t be removed from the
Shortcut app
even if we update our AppIntent with@available(iOS 17.0, *)
.Can you circumvent the bug by using "if #available(iOS 17, *)" syntax?