Source:http://mjtsai.com/blog/2014/11/21/ios-ipc-via-nsfilecoordinator-and-nsfilepresenter/

为什么每次我想到的东西,别人都已经研究了。⊙﹏⊙b汗

Tom Harrington:

There’s still no full IPC mechanism on iOS. NSDistributedNotification hasn’t made the jump from OS X to iOS and probably never will. But file coordination and presentation can serve the same purpose, as long as the apps use the same app group.

When I was adding file coordination and presentation to my demo app, I realized that they could also be used for notifications between an app and its extensions. If one of them does a coordinated write while the other is using a file presenter for the file, the call topresentedItemDidChange happens almost instantly. Notification is the whole purpose of that method, so it makes sense it would work this way. I want to be notified if a specific file changes, and that’s how I get the notification.

But you don’t need to care about the file contents to be interested in notifications. If you just want a notification, choose a file name and use it as the notification mechanism. Any time one process needs to notify the other, make a change to the file. The other will get a file presenter call, and the notification is complete. It feels sort of like a hack but really this is exactly how the API is designed to work.

Update (2014-11-22): Apple TN2408 (via JanApotheker):

Using file coordination in an app extension to access a container shared with its containing app may result in a deadlock. This is usually the case if a process is suspended mid coordinated I/O. This can be more prevalent on iOS where most apps will be suspended after a short period of time after being moved to the background. Extensions should use alternatives to file coordination.

[…]

Regardless of this issue, the containing app (and all applications) should properly use background task assertions around file operations they require completed in a shared container (with or without extensions). This includes all writes or deletions. Such a process might still be killed by jetsam but at a much lower frequency.

 

[转]iOS IPC via NSFileCoordinator and NSFilePresenter的更多相关文章

  1. iOS开发系列--App扩展开发

    概述 从iOS 8 开始Apple引入了扩展(Extension)用于增强系统应用服务和应用之间的交互.它的出现让自定义键盘.系统分享集成等这些依靠系统服务的开发变成了可能.WWDC 2016上众多更 ...

  2. iOS应用程序间共享数据

    我们知道iOS由于沙盒的存在,应用程序不能越过自己的区域去访问别的存储空间的内容,不过可能有许多场景我们需要在应用程序之间共享数据,比如多个应用共用用户名密码进行登录等.虽然我们不能直接通过文件系统来 ...

  3. iOS 通知中心扩展制作初步-b

    涉及的 Session 有 Creating Extensions for iOS and OS X, Part 1 Creating Extensions for iOS and OS X, Par ...

  4. AppExtention - today

    声明: 本文转自王巍 WWDC 2014 Session笔记 - iOS 通知中心扩展制作入门 本文是我的 WWDC 2014 笔记 中的一篇,涉及的 Session 有 Creating Exten ...

  5. File System Programming --- (一)

    About Files and Directories The file system is an important part of any operating system. After all, ...

  6. 细数iOS上的那些安全防护

    细数iOS上的那些安全防护  龙磊,黑雪,蒸米 @阿里巴巴移动安全 0x00 序 随着苹果对iOS系统多年的研发,iOS上的安全防护机制也是越来越多,越来越复杂.这对于刚接触iOS安全的研究人员来说非 ...

  7. iOS 保持界面流畅的技巧 (转载)

    这篇文章会非常详细的分析 iOS 界面构建中的各种性能问题以及对应的解决思路,同时给出一个开源的微博列表实现,通过实际的代码展示如何构建流畅的交互. Index 演示项目 屏幕显示图像的原理 卡顿产生 ...

  8. cocoa框架 for iOS

    1.Cocoa是什么? Cocoa是OS X和 iOS操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发中你可以使用各种语言:也不是开发工具,你可 ...

  9. 如何让iOS 保持界面流畅?这些技巧你知道吗

    如何让iOS 保持界面流畅?这些技巧你知道吗   作者:ibireme这篇文章会非常详细的分析 iOS 界面构建中的各种性能问题以及对应的解决思路,同时给出一个开源的微博列表实现,通过实际的代码展示如 ...

随机推荐

  1. ashx的学习

    原文:ashx的学习 嘿嘿,今天我们休息,本来是想总结一下前两周学习的javascript和jquery,但是感觉好困哦,就没有认真地学习啦,于是做了一个小小的练习,刚开始学习html使用在项目中还是 ...

  2. VS2013打包部署(图解)

    首先要说明的是VS解决方案的配置Debug模式和Release有什么区别模式.Debug模式通常被称为调试模式,它包括调试信息,不优化的代码,序:Release模式通常叫做公布模式.不包括调试信息,可 ...

  3. 【iOS发展-70】点菜系统案例:使用文本框inputView和inputAccessoryView串联UIPickerView、UIDatePicker和UIToolBar

    (1)效果 (2)先在storyboard中设计界面,然后源码(直接在ViewController中码) #import "ViewController.h" @interface ...

  4. linux_根据关键词_路径下递归查找code

    1:进入想查找的项目根目录 2:根据关键词查找 find . -name "*" |xargs grep -F '10.26'

  5. cocos2d 缓存池 对象的再利用

    1.简单的叙述说明池 例如,我们知道,游戏的游戏类型跑酷,游戏元素都在不断重复.游戏的内容将继续从屏幕右侧的创建,当元件在屏幕的左侧的,将消失.假设不变new 对象.release 对象 性能影响.怎 ...

  6. java_log4j 经典配置

    程序加载制定日志文件 public static final String log4j = "log4j.xml"; /** * @declare 加载log4j * @throw ...

  7. Jquery--仿制360右下角弹出窗口

    原文:Jquery--仿制360右下角弹出窗口 先发浏览器效果图,给大家看. 要实现这样的效果,按照思路,第一步,写好CSS布局,将图片放到浏览器右下角的位置 CSS代码很灵活,我写的只是简单的一种而 ...

  8. Robot Framework + appium 启动手机浏览器的两个方法(1)

    一.Open Browser启动 使用Selenium2Library的Open Browser方法,例子如下: browser=手机浏览器类型,如chrome 二.Open Application启 ...

  9. 编程算法 - 第一个仅仅出现一次的字符 代码(C)

    第一个仅仅出现一次的字符 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 在字符串中找出第一个仅仅出现一次的字符. 字符是char类型, 所以匹 ...

  10. jAVA 得到Map价值

    jAVA 获取Map中的值 Map<String, String> map=new HashMap<String, String>(); map.put("name& ...