I am writing a Swift framework that contains a Siri intentdefinition file and code that is used both from the main app, from a Today extension, and from a Siri intent extension. I am using Cocoapods to distribute the framework (it is in a private repo, so I cannot share the framework itself). This works well for compiling, linking, and executing code from within the app and the Today extension.
The app (or Today extension) successfully donates the intent when the user performs the corresponding action. I can then go to System Settings/Siri/Suggested Shortcuts and record a "personalized phrase" to trigger the intent.
When I invoke Siri using the recorded phrase, she responds with "I don't see an app for that. You'll need to download one."
I also noticed the following error message when donating the intent:
[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
The same code worked fine until I moved it into a framework, so I know the code is correct.
Apparently, the information contained within the intent that is donated is not sufficient for com.apple.notificationcenterui to be able to resolve the correct app to respond to the intent, which I find baffling. In order for the system to find the app successfully, the intentdefinition file must be contained in the app's main bundle. If you are not using Cocoapods, just can just check a box to include the intentdefinition file in the app's bundle, as Apple recommends in their Introduction to Siri Shortcuts WWDC video.
When using Cocoapods, this is problematic, in that the framework and the intentdefinition file are in a separate project within a workspace, so you can't just check a box to include the file in the app's bundle.
To solve this problem when using Cocoapods, I added the following to my app's 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
pod install
Now, each time you pod install
or pod update
, it will automatically put the latest intentdefinition where the compiler can include it in the app bundle and Siri is happy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With