Resolving a time interval in Siri Shortcuts

Viewed 179

I'm implementing Siri Shortcuts in my app. I have a duration property in my intent, and it's unit is set to minutes.

So the user has two options for providing a value for this property: 1. predefine it when creating the shortcut, 2. leaving it empty and filling it at the time of running the shortcut.

My problem is that when the value is predefined, or when the user fills it by typing (not voice command), it behaves like a TimeInterval object, so the value is in seconds (i.e. typing "2" returns 120.0). But when using voice command, it returns the result in minutes, and that is not what I want (i.e. saying "two" returns the number 2).

So I would like to know how can I get a consistent value, or how can I detect when the user used voice command or typing?

Here is my code for resolving this property:

func resolveTimeInterval(for intent: MyIntent, with completion: @escaping (INTimeIntervalResolutionResult) -> Void) {
    guard let timeInterval = intent.timeInterval else {
        completion(INTimeIntervalResolutionResult.needsValue())
        return
    }
    
    let timeIntervalDouble = timeInterval.doubleValue
    completion(INTimeIntervalResolutionResult.success(with: timeIntervalDouble))
}

And here is a screenshot of how this property is defined: enter image description here

0 Answers
Related