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?
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