How to return a default Intent configuration for Widget

Viewed 809

I want to return a default INIntent for my widget. In the automatically generated file, there is an optional method of the INIntentHandlerProviding protocol that allows you to specify the default configuration for your widgets.

For me, it looks something like:

defaultIntentParameter(for intent: ConfigurationIntent) -> MyCustomINObject

I manage to make this work, but it only works once. I can't change this dynamically based on date or any other parameters.

Has anyone else had experience with this and managed to get around it?

1 Answers

/*! @abstract Default values for parameters with dynamic options @discussion Called to query the parameter default value. */ @available(iOS 14.0, macOS 10.16, watchOS 7.0, *) @objc(defaultChartTypeForConfiguration:)
optional func defaultChartType(for intent: ConfigurationIntent) -> Chart?

In your IntentHandler file, add the default function so will display default as well. Change the Task to be the parameter from intent TaskIntent is the name of the Typeenter image description here

class IntentHandler: INExtension, DynamicTaskIntentHandling {
    func defaultTask(for _: DynamicTaskIntent) -> TaskIntent? {
        TaskIntent(identifier: "default", display: "Test")
    }
Related