iOS Siri Intents 扩展 "I don't see an app for that. You'll need to download one."

iOS Siri Intents Extension "I don't see an app for that. You'll need to download one."

我正在编写一个 Swift 框架,其中包含一个 Siri intentdefinition 文件和代码,主应用程序、Today 扩展和 Siri intent 扩展都使用了这些代码。我正在使用 Cocoapods 来分发框架(它在私人仓库中,所以我无法共享框架本身)。这适用于从应用程序和 Today 扩展中编译、链接和执行代码。

应用程序(或 Today 扩展程序)在用户执行相应操作时成功提供了意图。然后我可以转到系统 Settings/Siri/Suggested 快捷方式并记录一个 "personalized phrase" 来触发意图。

当我使用录制的短语调用 Siri 时,她回应 "I don't see an app for that. You'll need to download one."

我在捐赠意图时也注意到以下错误信息:

[Intents] -[INIntentResponse init] App proxy < com.company.appID file:///Users/username/Library/Developer/CoreSimulator/Devices/.../data/Containers/Bundle/Application/.../AppName.app :0>> doesn't contain intent nameOfIntent, falling back to current bundle

相同的代码在我将其移入框架之前工作正常,所以我知道代码是正确的。

显然,捐赠的意图中包含的信息不足以让 com.apple.notificationcenterui 能够解析正确的应用程序来响应意图,我觉得这令人费解。为了让系统成功找到应用程序,intentdefinition 文件必须包含在应用程序的主包中。如果您不使用 Cocoapods,只需选中一个框以将 intentdefinition 文件包含在应用程序的捆绑包中,正如 Apple 在其 Introduction to Siri Shortcuts WWDC video.

中所建议的那样

使用 Cocoapods 时,这是有问题的,因为框架和 intentdefinition 文件位于工作区内的单独项目中,因此您不能只选中一个框以将文件包含在应用程序的包中。

为了在使用 Cocoapods 时解决这个问题,我在我的应用程序的 podfile 中添加了以下内容:

post_install do |installer|
  require 'fileutils'
  # Copy Siri intentdefinition file from framework to app's resource folder, then use "Copy Bundle Resources" phase to copy it into app's main bundle
  FileUtils.cp_r('Pods/FrameworkName/FrameworkName/Base.lproj/Intents.intentdefinition', 'Resources/Intents.intentdefinition', :remove_destination => true)
end
  1. 运行 pod install
  2. 导航到您的应用目标 "Build Phases"/"Copy Bundle Resources"
  3. 点击列表底部的“+”按钮
  4. 点击提示底部的"Add Other..."
  5. 导航到您应用的 "Resources" 文件夹
  6. Select Intent.intentdefinition 文件,该文件应该已经在步骤 #1
  7. 的文件夹中

现在,每次您 pod installpod update,它都会自动将最新的 intentdefinition 放在编译器可以将其包含在应用程序包中的位置,Siri 很高兴。