Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Errors with intent parameters and Dynamic options with Siri

  • I've an intent parameter set as dynamic from the intent definition.

  • Let's say that the server where I get information for this option is currently down.

It is not clear how to present to users the fact that the options at the moment cannot be retrieved. The completion field where we should return the options also accepts an Error. I've filled it with a subclass of Error and I've also implemented the LocalizedError protocol for this class... but when I encounter the error from the shortcut App, Apple is just presenting a pop up message that returns a terrible message not localized (but that includes the right Error name).

Here is the code that I'm using...

func provideCarModelOptions(for intent: CarIntent, with completion: @escaping ([String]?, Error?) -> Void) {

    if(somethingGoesWrongWithServers()){
        completion([],CarError.ServerDown)
    }else{
        completion(ReturnListOfModels(), nil)
    }
}

And this is how I've implementend the CarError enum

public enum CarError:Error{
    case serverDown
    case generic
}

extension CarError : LocalizedError{
    public var errorDescription: String? {
        switch self {

        case .serverDown:
            return "Server is down"

        case .generic:
            return "SomethingGoesWrong"

        }

    }
}

Am I doing anything wrong or Apple is not handling the Errors the right way?

like image 639
MatterGoal Avatar asked Nov 14 '19 16:11

MatterGoal


People also ask

What is an intent Siri?

The Intents and IntentsUI frameworks drive interactions that start with “Hey Siri…”, Shortcuts actions, and widget configuration. The system also incorporates intents and user activities your app donates into contextual suggestions in Maps, Calendar, Watch complications, widgets, and search results.

How do I install Siri shortcuts?

Tap add to Siri, then select the task you'd like to add to shortcuts. Customize the phrase you use to activate the shortcut. Save when you are done.

How do I add Siri to IOS app?

If you didn't set up Siri when you first set up your iPhone, go to Settings > Siri & Search, then do any of the following: If you want to activate Siri with your voice: Turn on Listen for “Hey Siri.”


1 Answers

This worked for me to provide localized description:

completion(nil, INIntentError.init(_nsError: NSError(domain: "com.Domain.error", code: 0, userInfo: [NSLocalizedDescriptionKey: "Error Message"])))
like image 109
youthdancing Avatar answered Oct 01 '22 04:10

youthdancing