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?
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.
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.
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.”
This worked for me to provide localized description:
completion(nil, INIntentError.init(_nsError: NSError(domain: "com.Domain.error", code: 0, userInfo: [NSLocalizedDescriptionKey: "Error Message"])))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With