Restricting available units for a Measurement<UnitDuration> @Parameter

Hello,

I'm preparing my app Tameno for iOS 18, adding a couple of Control Center widgets.

One of them allows users to select their favorite interval. But in the context of my app, only seconds and minutes make sense as a unit value - I don't need milli-pseconds, nor hours.

Is there a way restrict these available options that come from a ControlConfigurationIntent?

@available(iOS 18.0, iOSApplicationExtension 18.0, *)
struct TamenoFavoriteIntervalControlWidgetSetupIntent : ControlConfigurationIntent {
	static let title: LocalizedStringResource = "cw_FavoriteIntervalSetup"
	static let isDiscoverable: Bool = false
	
	@Parameter(title: "cw_IntervalParameter", defaultValue: 5.0, defaultUnit: .seconds, supportsNegativeNumbers: false) var interval: Measurement<UnitDuration>?
	
	@MainActor
	func perform() async throws -> some IntentResult {
		.result()
	}
}

I am able to restrict it just to seconds or minutes only (by adding unit: .seconds, or unit: .minutes to the @Parameter setup), but I'd really like to offer both.

Thank you,

  • Matthias
Answered by Engineer in 804650022

Hi,

From our documentation of ControlConfigurationIntent

struct FocusOptionsProvider: DynamicOptionsProvider {
        func results() async throws -> [Focus] {
            FocusManager.shared.allFocuses
        }
    }
    
@Parameter(title: "Focus", optionsProvider: FocusOptionsProvider())

DynamicOptionsProvider allows you to customize this.

Rico

WWDR - DTS - Software Engineer

Any insights?

Hi,

From our documentation of ControlConfigurationIntent

struct FocusOptionsProvider: DynamicOptionsProvider {
        func results() async throws -> [Focus] {
            FocusManager.shared.allFocuses
        }
    }
    
@Parameter(title: "Focus", optionsProvider: FocusOptionsProvider())

DynamicOptionsProvider allows you to customize this.

Rico

WWDR - DTS - Software Engineer

I see, but I don't want to offer a fixed list of all possible intervals, I just want to be able to restrict the user from being able to select all offered UnitDurations (milliseconds, picoseconds, microseconds, nanoseconds, seconds, minutes, hours) to just two: seconds and minutes.
I don't see how I can accomplish this with a DynamicOptionsProvider.

Thank you for your help.

Restricting available units for a Measurement&lt;UnitDuration&gt; @Parameter
 
 
Q