[转]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 界面构建中的各种性能问题以及对应的解决思路,同时给出一个开源的微博列表实现,通过实际的代码展示如 ...
随机推荐
- 【iOS开展-94】xcode6如何使用GIT以及如何添加太老项目GIT特征?
(1)对于一个新项目:如何使用GIT?在新项目的过程,例如,您可以选择下面的复选框. (2)针对老项目,加入GIT功能. --在终端.cd到项目文件夹 --然后输入git init,初始化一个.git ...
- VC编程 快捷键增加的几种方式
VB运行时菜单字母的下划线消失 vc 给菜单增加快捷键RT给Menu里面的 文件 帮助 查看 等功能键加上一个快捷方式.比如按Ctrl+F1 就弹出查看下面的子功能.------解决方案------- ...
- java中的反射,invoke方法[转]
在施老师的项目中需要用到invoke,就是通过函数名反射相应的函数.一下代码简单地介绍了java反射中invoke方法,如果要具体的,可以参考魔乐核心课程的反射部分内容 package org.cur ...
- swiftSingleton模式
swift在几个方面Singleton模式: 1. 全局变量 private let _singleton = Singleton() class Singleton: NSObject { clas ...
- oracle_五千万数据插入测试
--创建表 tab_a -- create table tab_a (id int primary key not null,pid int); --创建序列 /** create sequence ...
- ASP.NET 5- 1
ASP.NET 5 入门(1) - 建立和开发ASP.NET 5 项目 ASP.NET入门(1) - 建立和开发ASP.NET 5 项目 建立项目 首先,目前只有VS 2015支持开发最新的ASP ...
- Advance Installer安装问题
一,在Advance Installer中注冊dll 1,首先将文件加入到Files And Folders中.此处以InstallValidate.dll为例. 2,在Custom Action处进 ...
- Socket 学习(三).4 UDP 穿透 客户端与客户端连接
效果图: 使用方法: 先 修改WinClient\bin\Debug 下面的 ip.ini,写上 服务器 IP地址. 客户端 与 客户端 通讯 之前 ,点击发送打洞消息 按钮,然后过一会再发送消息 ...
- Asp.net MVC + EF + Spring.Net 项目实践(一)
准备用几篇文章来做一个MVC的例子,为了给新同事做参考,也为自己做个知识储备. 首先,用VS2013创建一个空白解决方案StudentManageSystem,然后添加一个MVC应用程序(可参考ASP ...
- Windows Phone 8.1 多媒体(3):音乐
原文:Windows Phone 8.1 多媒体(3):音乐 Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone ...