6

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
glv19
  • 474
  • 6
  • 16

3 Answers3

2

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.

greg
  • 4,843
  • 32
  • 47
  • In my case I've added my main application in .intentdefinition's target but still getting same issue. – Bhavesh Mar 22 '19 at 09:15
  • 1
    I works fine when I debug it on simulator but throwing error on real device. – Bhavesh Mar 22 '19 at 09:33
  • @Bhavesh Did you find root cause of this issue? I have the same setup and it works on the simulator in debug, but fails on the real device. – SerJ_G May 29 '19 at 16:25
  • Thank you so much! I just moved everything to a custom framework and was wondering why the shortcuts did not show up! – Klaas Oct 02 '19 at 08:11
0

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

mtrevia
  • 186
  • 1
  • 3
  • Thanks for your answer. I did try this but still got the same error message. In the end I was able to get this to work by creating a reference to the .intentdefinition file in my application folder. I've added an answer with some more info on how I got it to work. – glv19 Jun 12 '18 at 17:21
0

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.

glv19
  • 474
  • 6
  • 16