Home > Software design >  Multiple intents won't run
Multiple intents won't run

Time:10-31

I have two intents that I am trying to run using Shortcuts app.

This is the tests I have ran in IntentHandler:

This works:

class IntentHandler: INExtension {
    override func handler(for intent: INIntent) -> Any? {
        
        guard intent is CarIDIntent else {
            return .none
         }
         return AccessTokenIntentHandler()
     }
 }

This works:

class IntentHandler: INExtension {
    override func handler(for intent: INIntent) -> Any? {
        
        guard intent is AccessTokenIntent else {
            return .none
        }
        return AccessTokenIntentHandler()
     }
 }

This does not work:

class IntentHandler: INExtension {
    override func handler(for intent: INIntent) -> Any? {
        
        guard intent is AccessTokenIntent else {
            return .none
        }
        
        guard intent is CarIDIntent else {
            return .none
        }
        
        return AccessTokenIntentHandler()
     }
 }

What am I doing wrong here? Both of them are added to the Intents.intentdefinition file.

CodePudding user response:

As Fad1611 mentioned, you could try using a switch case. Since you haven't given any information about what the error tells you it's hard to find a exact solution, but try this:

class IntentHandler: INExtension {
    override func handler(for intent: INIntent) -> Any? {
        switch intent {
        case is AccessTokenIntent:
            print("Access Token")
        case is CarIDIntent:
            print("Car ID")
        default:
            return .none
        }
        return AccessTokenIntentHandler()
     }
 }

CodePudding user response:

What type of error you get? you must specify more details. I also would say that you can use a switch case if you have more than one possibility.

  • Related