glv19
glv19

Reputation: 486

SiriKit Error: Donating intent is not supported by this application

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).

enter image description here

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).

enter image description here

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?

Upvotes: 6

Views: 3545

Answers (3)

greg
greg

Reputation: 4953

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.

Upvotes: 2

glv19
glv19

Reputation: 486

I've been able to get this to work by adding a reference to the CustomIntents.intentdefinition file in the application folder by dragging the .intentdefinition file into my application folder as well as my custom framework folder (see image below):

enter image description here

When copying the file, I made sure made sure not to check the 'Copy items if needed' option so the .intentdefinition file only exists in one place:

enter image description here

After running and testing on a device, the interaction is donated successfully and the app now offers 'Order Test Product' as an option under 'Siri & Search' in the device settings.

Upvotes: 0

mtrevia
mtrevia

Reputation: 186

Try removing the word "Intent" from "OrderIntent" string on your NSExtension -> NSExtensionAttributes -> IntentsSupported.

i.e. Your path will be something like NSExtension -> NSExtensionAttributes -> IntentsSupported -> Item 0 -> Order.

I know that the Apple Documentation states that we should:

Set the value of each item to the class name of the intent

But for me, it doesn't work at all.

Hope that helps you :)

Upvotes: 0

Related Questions