Ensuring 'Today' extension has updated information from Core Data

这一生的挚爱 提交于 2019-12-13 00:40:31

问题


I have an application and a today extension that are sharing a Core Data persistent store using a security group identifier.

The main app updates the Core Data store and the extension only reads from the store.

I am using a NSFetchedResultsController in both the app and the extension to retrieve the objects.

This basically works, except that when the main app adds new objects to the store they aren't visible to the extension immediately. Similarly the extension can still see objects after they have been deleted by the main app.

Terminating the app (swiping up from the task switcher) causes the extension to see the changed data immediately.

How can I ensure that the extension always sees the update?


回答1:


I found the solution was to remove the cached data from the NSFetchedResultsController in the today extension. I added the following line to my code that set up the NSFetchedResultsController

 [NSFetchedResultsController deleteCacheWithName:self.fetchedResultsController.cacheName];


来源:https://stackoverflow.com/questions/27959325/ensuring-today-extension-has-updated-information-from-core-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!