我有几个使用 iOS 17 特定功能的 AppIntents,因此用
@available(iOS 17.0, *)
进行注释。 AppIntent 仅在 iOS 17 上的“快捷方式”应用程序中正确列出,并在 iOS 16 上隐藏。但是,如果我在应用程序快捷方式中引用这些 AppIntent,则 AppShortCut 也会出现在 iOS 16 上,即使 AppIntent 仅适用于 iOS 17,甚至是AppShortcutsProvider 带有 @available(iOS 17.0, *)
注释。当用户在 iOS 16 上点击应用程序快捷方式时,会导致应用程序崩溃。
示例代码:
@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"
)
]
}
}
如果有任何有关如何在 iOS 16 上创建应用程序快捷方式而不崩溃的提示,我将不胜感激。
我尝试使用示例应用程序检查您的示例代码,该示例应用程序的最小部署目标是 Xcode(15.3) 中的
iOS 16.0
。
我使用提供的简单代码没有遇到任何崩溃问题。
并且那些带有
Appintents
的 @available(iOS 17.0, *)
在 iOS 16.0
快捷方式列表中不可见。
所以我的猜测是您的旧 AppIntent 以某种方式使用了
iOS 17.0
引入的功能。这可以通过以下方式实现-
HelloIntent
,AppIntent 为 HelloIntent
。HelloIntent
标签 @available(iOS 17.0, *)
并使用一些 iOS 17.0 功能。 (例如 - ParameterDependency
)。并构建项目。HelloIntent
快捷方式。HelloIntent
快捷方式崩溃。因为即使我们使用
Shortcut app
更新 AppIntent,已创建的快捷方式也不会从 @available(iOS 17.0, *)
中删除。