Hello everybody!
Does anybody know how to set default values for string array intent field provided dynamically? I want to have preset array field values just after widget added
I have a simple accessory widget with circular and rectangular representation (the first one is for 1 currency value and the second one is for 3 values).
I created CurrencyWidgets.intentdefinition and added AccessoryCurrency custom intent. Here I added string parameter field currencyCode. For this parameter I set the following options:
Supports Multiple Values
Fixed Size (AccessoryCircular = 1, AccessoryRectangular = 3)
User can edit value in Shortcuts
Options are provided dynamically
Then I created CurrencyTypeIntent extension and added IntentHandler for my custom intent AccessoryCurrency. The code is below
class IntentHandler: INExtension, AccessoryCurrencyIntentHandling {
override func handler(for intent: INIntent) -> Any { self }
func provideCurrencyCodeOptionsCollection(for intent: AccessoryCurrencyIntent) async throws -> INObjectCollection<NSString> {
return INObjectCollection(items: [NSString("USD"), NSString("EUR"), NSString("RUB"), NSString("CNY")])
}
func defaultCurrencyCode(for intent: AccessoryCurrencyIntent) -> [String]? {
return ["USD", "EUR", "RUB"]
}
}
The problem is in func defaultCurrencyCode(...): when I return something except nil (for example ["USD"] or ["USD", "EUR", "RUB"]) then I got a broken widget. It hangs in a placeholder state in lock screen and at add widget UI (see the image below).
Otherwise when I return nil then my widget works fine. But when I try to customise widget then I don't have default values for my currencyCode field, only Chose placeholders.
At the same time everything works fine for the single string parameter (without "Supports Multiple Values"). Does anybody know how to make default parameters work for array (multiple) field?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
WidgetKit
Intents
App Intents