问题
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