Action Extension AND Sharing Core Data

前提是你 提交于 2019-12-02 09:17:42

问题


I am using the Action extension in my Application.

Our app currently uses Core Data. I am sharing this between the app and the Action Extension using App Groups and successfully migrated the Core Data from Documents Directory to App Group.

The problem which I am facing happens when importing photos or notes from Photos/Notes App into my application using the extension. The document is imported successfully but I am not able to view that document in my application. Only when I kill the application and run it again then the documents appear.

I am not using a framework here. So I have different code files in Application and Extension using the same Store. I have used different Managed Object Contexts. Even though I am reloading the data in the application after performing Action Extension work, items are not visible unless I kill the application and launch it again.

What could be the issue and how to resolve this?


回答1:


The problem you describe happens because there's no notification to tell your app that there's new data in the persistent store file, so it just keeps showing the existing data. You need to handle this yourself.

A simple approach is to observe UIApplicationDidBecomeActiveNotification in your app. Any time you receive that, reload your data. You'll get any new entries created by the extension.

A more sophisticated approach is to use something like MMWormhole to notify the app of new content. Then it would only load new entries when they actually exist, instead of reloading every time it becomes active.



来源:https://stackoverflow.com/questions/28197360/action-extension-and-sharing-core-data

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