1

I am not able to fetch data in my IntentHandler class. My Goal is select Todo from the CoreData list and display it in Widget. enter image description here

I am trying to display a list from CoreData in Widget Intent and I am expecting to resolve this issue.

extension IntentHandler : ConfigurationIntentHandling {
    func provideTodoNameOptionsCollection(for intent: ConfigurationIntent, searchTerm: String?, with completion: @escaping (INObjectCollection<TodoData>?, Error?) -> Void) {
        var arrTodoData = [TodoData]()
        coreDH.getAllTodos().forEach { todos in
            let todoIntent = TodoData(identifier: todos.id?.uuidString, display: todos.name ?? "")
            arrTodoData.append(todoIntent)
        }
        let collection = INObjectCollection(items: arrTodoData)
        completion(collection, nil)
    }
}

class IntentHandler: INExtension{
    let coreDH = CoreDataHandler.shared
    override func handler(for intent: INIntent) -> Any {
        // This is the default implementation.  If you want different objects to handle different intents,
        // you can override this and return the handler you want for that particular intent.
        return self
    }
}
Timmy
  • 4,098
  • 2
  • 14
  • 34
  • Please share your `IntentHandler` class code which you have done so far. – Hardik Shekhat Nov 01 '22 at 04:18
  • As per your requirement, I have sent the code of IntentHandler Class. But unfortunately, provideTodoNameOptionsCollection method is not called. – Bhavesh Rathod Nov 01 '22 at 06:47
  • 1
    Make sure you are actually sharing the data via AppGroup or some other form. Without a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) it is impossible to help you troubleshoot. – lorem ipsum Nov 01 '22 at 12:04

1 Answers1

1

If your IntentHandler doesn't get called:

If you need to share data between your app and extension:

  • App's data is sandboxed and is not accessible by extension
  • Configure App Groups and you could create core data file in the shared container to be able to access in your extension
  • If App and Extension use exactly the same data you could use the same sqlite file in the shared container (both app and extension would have access to it)
  • If App and Extension use different data and there is only a small portion that is common, then use History Tracking
  • Configuring App Groups
  • Consuming Relevant Store Changes
user1046037
  • 16,755
  • 12
  • 92
  • 138
  • do you know how to debug functions in IntentHandler? I ran the app scheme, and then the intent scheme, I picked the main app to run and it just launches my app with siri. I need it to run when showing a list of widget configuration options (which it does run) but I just want to debug it. How? – erotsppa Jun 29 '23 at 02:59
  • Refer: https://stackoverflow.com/a/74145087/1046037 – user1046037 Jun 29 '23 at 06:08