0

I'm trying to find a suitable mechanism to provide an image from the app to the widget. So far I had success with AppGroups and a fixed identifier. Saved the image in user defaults with a fixed ID on the app side and I could retrieve it on the widget side by accessing user defaults with my key.

But now I'm trying to get along with Siri Intents. I don't know how to provide image data from my app to my widget. How can I achieve that? I have seen other PhotoWidget apps on the store that are providing such functionality. For example Photo Widget App shows some UI when editing the widget where I can select a photo that has been chosen on the main app.

To sum up: How can I get a photo chosen from my app inside my widget with SiriIntents?

Any help is appreciated!

Nico S.
  • 3,056
  • 1
  • 30
  • 64

1 Answers1

0

In your Intent.intentdefinition file you could add Configurable parameters with Dynamic options: enter image description here

Then in IntentHandler file you could specify the source for available options. Example for names list from UserDefaults:

class IntentHandler: INExtension, IntentHandling {
    func provideNameOptionsCollection(for intent: Intent, searchTerm: String?, with completion: @escaping (INObjectCollection<NSString>?, Error?) -> Void) {
        let existingWidgets = UserDefaults(suiteName: "group.name")!.value(forKey: "widgetUnits") as! String   
        let names = existingWidgets.components(separatedBy: "|")
        
        let result = INObjectCollection<NSString>.init(items: names.map { NSString(string: $0) })
        completion(result, nil)
    }
}
Viktor Gavrilov
  • 830
  • 1
  • 8
  • 13