{"id":11267,"date":"2015-05-19T09:34:26","date_gmt":"2015-05-19T13:34:26","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11267"},"modified":"2015-07-28T10:01:45","modified_gmt":"2015-07-28T14:01:45","slug":"nsfilecoordinator-improvement-in-ios-8-2","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/05\/19\/nsfilecoordinator-improvement-in-ios-8-2\/","title":{"rendered":"NSFileCoordinator Improvement in iOS 8.2"},"content":{"rendered":"<p><a href=\"http:\/\/www.atomicbird.com\/blog\/file-coordination-fix\">Tom Harrington<\/a> (<a href=\"https:\/\/twitter.com\/atomicbird\/status\/600401372366831616\">tweet<\/a>):<\/p>\r\n<blockquote cite=\"http:\/\/www.atomicbird.com\/blog\/file-coordination-fix\"><p>However last week the tech note was updated, and the above section now reads:<\/p>\r\n<blockquote>\r\n  <p>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 <strong>in iOS 8.1.x and earlier<\/strong>. [emphasis mine]<\/p>\r\n<\/blockquote>\r\n<p>That&rsquo;s great! In iOS 8.2 or higher, the obvious approach should now be safe.<\/p>\r\n<\/blockquote>\r\n<p>Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2014\/11\/21\/ios-ipc-via-nsfilecoordinator-and-nsfilepresenter\/\">iOS IPC via NSFileCoordinator and NSFilePresenter<\/a>.<\/p>\r\n<p>Update (2015-07-28): <a href=\"http:\/\/martiancraft.com\/blog\/2015\/06\/shared-core-data\/\">Richard Turton<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/martiancraft.com\/blog\/2015\/06\/shared-core-data\/\">\r\n<p>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\u2019t start reading the file before it is written. <code>NSDictionary<\/code> has a <code>writeToURL: atomically:<\/code> method that can be used for this.<\/p>\r\n<p>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 <code>FolderWatcher<\/code> class in the linked project.<\/p>\r\n<p>[\u2026]<\/p>\r\n<p>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.<\/p>\r\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>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, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,905,1121,31,904,71],"class_list":["post-11267","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-extensions","tag-ipc","tag-ios","tag-ios-8","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=11267"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11267\/revisions"}],"predecessor-version":[{"id":11852,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11267\/revisions\/11852"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}