There are hundreds of functions in my project that require creating shortcuts, but AppShortcutsProvider only supports up to 10 AppShortcut declarations, so I used over 100 AppIntents for users to manually add shortcuts (I did not add them to AppShortcutsProvider); The problem now is that I hope all the AppIntents I declare have specific names and function icons. I have tried my best to configure AppIntents with the query document, but the default display in the shortcut app is the icon of this application instead of the function icon I set. My code is as follows:
struct ResizeImageIntent: AppIntent {
static var title: LocalizedStringResource = "修改图片尺寸"
static var description: IntentDescription = IntentDescription("快速打开修改图片尺寸功能")
static var openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult {
if let url = URL(string: "toolbox://resizeimage") {
await UIApplication.shared.open(url)
}
return .result()
}
}
The following is the code with icon configuration added:
struct VideoParseIntent: AppIntent {
static var title: LocalizedStringResource = "万能解析"
static var description: IntentDescription = IntentDescription("快速打开万能解析功能")
static var openAppWhenRun: Bool = true
// 修正:返回AppShortcut数组
static var appShortcuts: [AppShortcut] {
[
AppShortcut(
intent: VideoParseIntent(),
phrases: ["使用万能解析"],
systemImageName: "play.rectangle.on.rectangle" // 系统内置图标
)
]
}
func perform() async throws -> some IntentResult {
if let url = URL(string: "toolbox://videoparse") {
await UIApplication.shared.open(url)
}
return .result()
}
}