TumblrArchive / ios-extension-issues

A collection of issues with iOS 8 share extensions, along with radar links, sample projects, and workarounds
204 stars 11 forks source link

`NSFileCoordinator` does not work reliably across applications and share extensions #3

Open irace opened 10 years ago

irace commented 10 years ago

NSUserDefaults and SQLite are useful for synchronizing data access across both extension and container application, but as per WWDC Session 217, NSFileCoordinator is also supposed to be an option for those of us using NSCoding for custom data persistence. We tried hard, but couldn’t actually get it to reliably work.

Our use case required both our app and extension to write to the same file, where only the app would read from it. We observed a number of problems while both extension and app processes were running simultaneously. NSFilePresenter methods intended to indicate that the file had been or will be modified (presentedItemDidChange or relinquishPresentedItemToWriter:) would either:

Rather than trying to keep access to a single file synchronized across processes, we modified our extension to instead atomically write individual files, which are never modified, into a directory that the application reads from.

This isn’t to say that NSFileCoordinator isn’t currently a viable option if you’ve got a different usage than we do. The New York Times app, for example, is successfully using NSFileCoordinator in a simpler setup, where the container app is write-only and the extension is read-only.

irace commented 9 years ago

This may now be fixed: http://www.atomicbird.com/blog/file-coordination-fix