简体   繁体   中英

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

在此输入图像描述

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.

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

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

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

在此输入图像描述

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:

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM