[转]iOS IPC via NSFileCoordinator and NSFilePresenter
Source:http://mjtsai.com/blog/2014/11/21/ios-ipc-via-nsfilecoordinator-and-nsfilepresenter/
为什么每次我想到的东西,别人都已经研究了。⊙﹏⊙b汗
There’s still no full IPC mechanism on iOS.
NSDistributedNotificationhasn’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 to
presentedItemDidChangehappens 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的更多相关文章
- iOS开发系列--App扩展开发
概述 从iOS 8 开始Apple引入了扩展(Extension)用于增强系统应用服务和应用之间的交互.它的出现让自定义键盘.系统分享集成等这些依靠系统服务的开发变成了可能.WWDC 2016上众多更 ...
- iOS应用程序间共享数据
我们知道iOS由于沙盒的存在,应用程序不能越过自己的区域去访问别的存储空间的内容,不过可能有许多场景我们需要在应用程序之间共享数据,比如多个应用共用用户名密码进行登录等.虽然我们不能直接通过文件系统来 ...
- iOS 通知中心扩展制作初步-b
涉及的 Session 有 Creating Extensions for iOS and OS X, Part 1 Creating Extensions for iOS and OS X, Par ...
- AppExtention - today
声明: 本文转自王巍 WWDC 2014 Session笔记 - iOS 通知中心扩展制作入门 本文是我的 WWDC 2014 笔记 中的一篇,涉及的 Session 有 Creating Exten ...
- File System Programming --- (一)
About Files and Directories The file system is an important part of any operating system. After all, ...
- 细数iOS上的那些安全防护
细数iOS上的那些安全防护 龙磊,黑雪,蒸米 @阿里巴巴移动安全 0x00 序 随着苹果对iOS系统多年的研发,iOS上的安全防护机制也是越来越多,越来越复杂.这对于刚接触iOS安全的研究人员来说非 ...
- iOS 保持界面流畅的技巧 (转载)
这篇文章会非常详细的分析 iOS 界面构建中的各种性能问题以及对应的解决思路,同时给出一个开源的微博列表实现,通过实际的代码展示如何构建流畅的交互. Index 演示项目 屏幕显示图像的原理 卡顿产生 ...
- cocoa框架 for iOS
1.Cocoa是什么? Cocoa是OS X和 iOS操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发中你可以使用各种语言:也不是开发工具,你可 ...
- 如何让iOS 保持界面流畅?这些技巧你知道吗
如何让iOS 保持界面流畅?这些技巧你知道吗 作者:ibireme这篇文章会非常详细的分析 iOS 界面构建中的各种性能问题以及对应的解决思路,同时给出一个开源的微博列表实现,通过实际的代码展示如 ...
随机推荐
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(2)-数据库访问层的设计Demo
原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(2)-数据库访问层的设计Demo ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1)框架搭建 前言:这 ...
- 深入探讨 Java 类加载器[转]
原文地址:http://www.ibm.com/developerworks/cn/java/j-lo-classloader/index.html 类加载器(class loader)是 Java™ ...
- Java串口通信详细解释
前言 说到开源.恐怕非常少有人不挑大指称赞. 学生通过开源码学到了知识,程序猿通过开源类库获得了别人的成功经验及可以按时完毕手头的project,商家通过开源软件赚到了钱……,总之是皆大欢喜. 然而开 ...
- Struts2流程
Struts2流程 1.client浏览器初始化时发出HTTP请求 2.依据web.xml配置,上述请求被FilterDispatcher接收 3.依据struts.xml配置,找到须要调用的Acti ...
- crawler_基础之_java.net.HttpURLConnection 访问网络资源
java访问网络资源 由底层到封装 为 scoket==> java.net.HttpURLConnection==>HttpClient 这次阐述先 java.net.HttpURL ...
- js拾遗:appendChild 添加移动节点
原文:js拾遗:appendChild 添加移动节点 写js一年多了,一直以为自己很牛逼,开始写各种博文分享,昨天写了一篇<浅谈 IE下innerHTML导致的问题>在看了下面的评论,我才 ...
- android 卸载程序、清除数据、停止服务用法
要实现卸载程序.清除数据.停止正在执行的服务这几大模块,如今将代码粗略总结例如以下: 主要运用到的类有 PackageManager ActivityManager ApplicationInfo R ...
- easyui datagrid shift 多选
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta na ...
- MVC 发布到 windows2003遇到 'System.Web.WebPages.Razor 错误提示
摘自: http://blog.csdn.net/lanqiao825/article/details/7840606 http://bbs.maticsoft.com/forum.php?mod=v ...
- TDD
初识TDD 首先说一下名词解释,TDD,英文名称Test-Driven Development,中文名称测试驱动开发,简单的断下句“测试/驱动/开发”,简单的理解一下,就是测试驱动着开发,大白话就是说 ...