I'm having problems donating a custom intent in Xcode 10 (iOS 12 Beta).
I've created a custom framework that's shared between my main app target, and my 'OrderIntent' target.
I've created a .intentdefinition file with the target membership set to my custom framework (screenshot below).
I've embedded an 'Intents Extension' & 'Intents UI Extension' within the main application.
I've also added the 'OrderIntent' to NSExtension->NSExtensionAttributes->IntentsSupported in both of the info.plist files created when I added the intents extensions (screenshot below).
I'm trying to donate the intent like this:
INPreferences.requestSiriAuthorization { (status) in
if status != INSiriAuthorizationStatus.authorized {return}
let orderIntent = OrderIntent()
orderIntent.product = "Test product"
orderIntent.quantity = 2
let interaction = INInteraction(intent: customIntent, response: nil)
interaction.donate { (error) in
if error != nil {2
if let error = error as NSError? {
print(error)
}
} else {
print("success")
}
}
}
The above code runs when a user taps on a button in the app.
I've also set up the intent handler like this:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
switch intent {
case is OrderIntent:
return OrderIntentHandler()
default:
fatalError()
}
return self
}
And the OrderIntentHandler like this:
public class OrderIntentHandler: NSObject, OrderIntentHandling {
public func handle(intent: OrderIntent, completion: @escaping (OrderIntentResponse) -> Void) {
let orderIntentResponse = OrderIntentResponse(code: OrderIntentResponseCode.success, userActivity: nil)
completion(orderIntentResponse)
}
public func confirm(intent: OrderIntent, completion: @escaping (OrderIntentResponse) -> Void) {
let response = OrderIntentResponse(code: OrderIntentResponseCode.ready, userActivity: nil)
completion(response)
}
}
When testing this on a device, I get the following error:
Error Domain=IntentsErrorDomain Code=1901 "Donating intent 'OrderIntent' is not supported by this application. Please make sure that you have an extension that supports this intent." UserInfo={NSLocalizedDescription=Donating intent 'OrderIntent' is not supported by this application. Please make sure that you have an extension that supports this intent.}
I can't understand why the 'OrderIntent' is not supported by the application.
I've already enabled Siri in the capabilities tab and requested permission from the user etc.
Are there any other steps that need to be taken to allow me to donate the intent?
I believe the answer to your problem is right in your description (emphasis mine):
I've created a .intentdefinition file with the target membership set to my custom framework
I'm assuming that the code executing the call to interaction.donate
is in your app and not in the shared framework. If this is the case (judging by your answer on how you worked around the problem), you also need to add your main application as a target from your .intentdefinition
file. You will want to have no generated classes since they're already in your shared framework that your app links to. You might have an issue, in that it looks like you created the shared framework in a separate Xcode project, and so the other targets are not visible.
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