Widget cannot retrieve Core Data on a real device.

My app uses Core Data and has enabled App Groups for data sharing between the App and Widget.

In my app, there's a Core Data entity called Task. As per the documentation's suggestion, I've separately implemented a TaskData struct that conforms to AppEntity. I've also implemented TaskDataQuery: EntityQuery, which includes a method called suggestedEntities. This method fetches all Tasks from the main context and uses Task.toTaskData.

Following the documentation, I've implemented the corresponding WidgetConfigurationIntent, which holds:

@Parameter(title: "Task") var task: TaskData

as well as the corresponding AppIntentTimelineProvider to implement the provider.

I haven't encountered any retrieval issues on the simulator; everything works perfectly.

However, the problem arises when I deploy to a physical device. Users report that their widgets can't retrieve any data. Specifically, when users long-press the widget to set up a task, it remains in a Loading state, unable to fetch any Core Data.

I've looked through some resources, and it seems this might be a common issue with iOS 17?

How can I resolve this issue? Has anyone encountered this or can offer any suggestions? This has been troubling me for several days now, and it's causing my product to continually lose users. I'm really upset about it.

Any advice is welcome.

The SwiftData version of The following Apple sample demonstrates an app + an interactive widget, which share a SwiftData store in an app group container:

It doesn't use Core Data directly, but in terms of data fetching and consuming, it is logically the same as your case because the SwiftData's default data store is based on Core Data.

Did you have a chance to try with the sample and see if it works for you? If it does, you can probably figure out how you do differently by comparing the two projects.

If this approach doesn't help, you might consider providing a minima project that contains only the code relevant to the issue, with detailed steps to reproduce the issue. Folks here may be able to help more effectively.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Widget cannot retrieve Core Data on a real device.
 
 
Q