确保“今天"扩展程序已更新了核心数据中的信息 [英] Ensuring 'Today' extension has updated information from Core Data
问题描述
我有一个应用程序和一个今天的扩展程序,它们使用安全组标识符共享Core Data持久存储.
I have an application and a today extension that are sharing a Core Data persistent store using a security group identifier.
主应用程序更新Core Data存储,并且扩展名仅从该存储中读取.
The main app updates the Core Data store and the extension only reads from the store.
我在应用程序和扩展程序中都使用NSFetchedResultsController
来检索对象.
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?
推荐答案
我发现解决方案是从今天扩展中的NSFetchedResultsController
中删除缓存的数据.我将以下行添加到我的代码中,以设置NSFetchedResultsController
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];
这篇关于确保“今天"扩展程序已更新了核心数据中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!