Tuesday, May 19, 2015

NSFileCoordinator Improvement in iOS 8.2

Tom Harrington (tweet):

However last week the tech note was updated, and the above section now reads:

When you create a shared container for use by an app extension and its containing app in iOS 8.0 or later, you are obliged to write to that container in a coordinated manner to avoid data corruption. However, you must not use file coordination APIs directly for this in iOS 8.1.x and earlier. [emphasis mine]

That’s great! In iOS 8.2 or higher, the obvious approach should now be safe.

Previously: iOS IPC via NSFileCoordinator and NSFilePresenter.

Update (2015-07-28): Richard Turton:

This dictionary can then be written to a specified location in the shared folder. The write has to be atomic, to ensure that the other processes don’t start reading the file before it is written. NSDictionary has a writeToURL: atomically: method that can be used for this.

Interested members of the app group can then detect the writing of this file by monitoring a folder using GCD. The details of this can be seen in the FolderWatcher class in the linked project.


The limitations of the Darwin Notification Centre and the complexities of writing to and reading from a file make the above solution suitable for only a small number of cases.

Comments RSS · Twitter

Leave a Comment