IntentHandler Not Being Called

I want to use Siri to perform a repetitive task in my app that inputs variable parameters, thus accelerating the input of that data.

I have implemented a couple custom intents for background execution with the use of an intentDefinition file and implemented an IntentsExtension and associated plist to enable those custom intents. I can successfully donate an interaction that iOS matches with the supported suggestions in the intentsDefinition file that causes a Siri Suggestion to be displayed in Siri Search (or on the lock screen when enabled):

    CreatePartsListIntent* createPartsListIntent = [[CreatePartsListIntent alloc] init];

    createPartsListIntent.projectName = intentData.projectName;

    createPartsListIntent.quantity = intentData.quantity;

   INInteraction* interaction = [[INInteraction alloc] initWithIntent:createPartsListIntent response:nil];

    [interaction donateInteractionWithCompletion:^(NSError * _Nullable error) {
        if(!error) {
            NSLog(@"CreatePartsList donation success");
        }else {
            NSLog(@"CreatePartsList donation fail %@",error.localizedDescription);
        }
    }];

I can then tap on this suggestion and it takes me to my appDelegate to process the interaction within the app

- (id)application:(UIApplication *)application handlerForIntent:(INIntent *)intent {
    // This method is called when I tap on the Siri suggestion
}

But I want to process the interaction in the background using voice commands. When I speak the the command of the interaction I donated, the IntentHandler is never called. I cannot figure out what I need to do to get the IntentHandler to be called. According to the WWDC18 Intro to Siri Shortcuts, I should be able to invoke a dialog with Siri, which is my goal.

Am I off track. Why isn't the IntentHandler being called? What should trigger it to be called?

Replies

Your users should create Shortcuts with custom phrases that will invoke your custom intent. You can suggest Voice Shortcuts to users in your app with addVoiceShortcutViewControlleer. Our Soup Chef sample has a good example of this.

  • @ricob I have done this. The problem is that the handlerForIntent is not being called (neither are any of the resolve, confirm, or handle methods). The only thing that is being called is the application:continueUserActivity:restorationHandler in my app delegate. The userActivity being called is my customIntent. What might be the reason that the handlerForIntent is not being called? According to the discussion in the documentation for application:continueUserActivity:restorationHandler: (under Handling Activities from SiriKit), the

    "Intents may launch your app under the following circumstances: Some intents always launch the app after the intent is successfully handled (for example, intents with a continueInApp response code). Your intent's handle and confirm methods launch the app when you resolve the intent with a failureRequiringAppLaunch (or similar) response code."

    But I have breakpoints set in the handlerForIntents and each of the resolve, confirm, and handle methods. Is there some other entry point I should look for?

Add a Comment