如何通过编程创建触发Phone应用拨打电话的Siri快捷指令?
解答
核心结论
直接通过代码自动创建指向Phone应用的Siri快捷指令(无需用户手动确认)不可行。原因在于:
INUIAddVoiceShortcutViewController仅支持创建自家App自定义的Intent快捷指令,无法操作系统App(如Phone)的系统级Intent(比如INStartCallIntent)。- 苹果出于隐私与安全限制,禁止第三方App绕过用户交互直接创建系统级快捷指令。
替代方案:预填充快捷指令创建表单
你提到的shortcuts://create-shortcut URL Scheme支持通过参数预填充表单内容,只需构造包含指定动作与参数的URL即可,具体实现如下:
代码示例
// 构造预填充拨打指定号码的快捷指令URL func openPreFilledCallShortcut(number: String, shortcutName: String) { // 构造动作的JSON结构 let action = [ "name": "Call", "parameters": ["number": number] ] guard let actionData = try? JSONSerialization.data(withJSONObject: [action]), let actionString = String(data: actionData, encoding: .utf8)?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let shortcutURL = URL(string: "shortcuts://create-shortcut?name=\(shortcutName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)&actions=\(actionString)") else { return } if UIApplication.shared.canOpenURL(shortcutURL) { UIApplication.shared.open(shortcutURL) } } // 调用示例:拨打1234567890,快捷指令命名为"拨打紧急电话" openPreFilledCallShortcut(number: "1234567890", shortcutName: "拨打紧急电话")
关键说明
- 该方式会打开快捷指令App的创建页面,自动填入“拨打指定号码”的动作与目标号码,用户只需点击“添加快捷指令”即可完成创建。
- 需确保你的App已在
Info.plist中添加shortcuts的查询权限:
<key>LSApplicationQueriesSchemes</key> <array> <string>shortcuts</string> </array>
- JSON参数必须做URL编码转义,避免出现解析错误。
内容的提问来源于stack exchange,提问作者Żabojad
相关产品推荐
相关产品推荐

