AppIntent和AppShortcutsProvider与Siri不兼容,无法正常工作。

3
我有一个非常简单的AppIntentAppShortcutsProvider。它在快捷方式应用程序中运行得很好,但是当询问Siri时就无法工作。
// MARK: - OpenLibrary
struct OpenLibrary: AppIntent {
    static let title: LocalizedStringResource = "Open Library"
    static let description = IntentDescription("Opens your saved songs and playlists.")
    static var openAppWhenRun: Bool = true
    
    @MainActor
    func perform() async throws -> some IntentResult & ReturnsValue {
        
        if let url = URL(string: "appName://library/open") {
            await UIApplication.shared.open(url)
        }
        return .result()
    }

}

struct OpenLibraryShortcutsProvider: AppShortcutsProvider {
    static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: OpenLibrary(),
            phrases: [
                "Open Library in \(.applicationName)",
                "Open \(.applicationName) Library",
                "Open my library in \(.applicationName)",
                "Open my \(.applicationName) Library"
            ],
            shortTitle: "Open Library",
            systemImageName: "rectangle.stack.fill"
        )
    }
    
    static var shortcutTileColor: ShortcutTileColor = .lightBlue
}

我对Siri说,在我的iPhone上,“打开我的{appName}图书馆”,然后Siri回答说“{appName}还没有与Siri添加支持”。正如我之前提到的,如果我将其创建并作为快捷方式运行,它可以正常工作。URL被正确处理。
我现在正在学习AppIntent。下一步我可以尝试什么?
1个回答

0
首先,在"签名和能力"中添加Siri。
据我所知,您需要在应用程序打开时使用Siri调用一个AppShortcut短语。然后,这将触发一个对话框,询问是否要"使用Siri启动<应用程序名称>"?如果用户选择"启动",则快捷方式将开始在iPhone的任何位置工作。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接