Commonly used in communication between iOS (APP) 8 summarizes the process

 

iOS system is relatively closed system, App run in their own sandbox (sandbox), each can only be read on the iPhone App iOS file system for the application program to create the folder contents of the AppData, not at liberty to cross own sandbox to access the contents of other App sandbox.

Write pictures described here

App manner so inter-system communication iOS relatively fixed, app communication between common use scenario and summarized below.

1、 URL Scheme

This is the communication app communication iOS most commonly used, by the method openURL App1 jump to App2, and to bring the desired parameter in the URL, http get request is somewhat similar to that parameter passing. This approach is the most used of the most common usage is also very simple to configure LSApplicationQueriesSchemes only source App1 in info.plist, specify the target App2's scheme; then configure URL types in info.plist target App2's, indicates that the what evokes the app URL scheme accepted.

Write pictures described here

A typical usage scenario is the Open Platform SDK sharing features, such as micro-channel circle of friends to share microblogging, or pay a scene. For example, a taxi from the end of the trip and pieces Jump to micro-channel payment.

Write pictures described here

2、 Keychain

Keychain iOS system is a secure storage container, it is essentially a database sqllite, its location is stored in /private/var/Keychains/keychain-2.db, but it holds all the data is encrypted, It can be used to store sensitive information to a different app, such as user name, password, and so on. iOS system to save himself with a keychain VPN credentials and Wi-Fi passwords. It is independent of the sandbox of each App, so even after the App is deleted, Keychain inside information still exists.

基于安全和独立于app沙盒的两个特性,Keychain主要用于给app保存登录和身份凭证等敏感信息,这样只要用户登录过,即使用户删除了app重新安装也不需要重新登录。

那Keychain用于App间通信的一个典型场景也和app的登录相关,就是统一账户登录平台。使用同一个账号平台的多个app,只要其中一个app用户进行了登录,其他app就可以实现自动登录不需要用户多次输入账号和密码。一般开放平台都会提供登录SDK,在这个SDK内部就可以把登录相关的信息都写到keychain中,这样如果多个app都集成了这个SDK,那么就可以实现统一账户登录了。

Keychain的使用比较简单,使用iOS系统提供的类KeychainItemWrapper,并通过keychain access groups就可以在应用之间共享keychain中的数据的数据了。

Write pictures described here

3、 UIPasteboard

顾名思义, UIPasteboard是剪切板功能,因为iOS的原生控件UITextView,UITextField 、UIWebView,我们在使用时如果长按,就会出现复制、剪切、选中、全选、粘贴等功能,这个就是利用了系统剪切板功能来实现的。而每一个App都可以去访问系统剪切板,所以就能够通过系统剪贴板进行App间的数据传输了。 
UIPasteboard的使用很简单,

Write pictures described here

UIPasteboard典型的使用场景就是淘宝跟微信/QQ的链接分享。由于腾讯和阿里的公司战略,腾讯在微信和qq中都屏蔽了淘宝的链接。那如果淘宝用户想通过QQ或者微信跟好友分享某个淘宝商品,怎么办呢? 阿里的工程师就巧妙的利用剪贴板实现了这个功能。首先淘宝app中将链接自定义成淘口令,引导用户进行复制,并去QQ好友对话中粘贴。然后QQ好友收到消息后再打开自己的淘宝app,淘宝app每次从后台切到前台时,就会检查系统剪切板中是否有淘口令,如果有淘口令就进行解析并跳转到对于的商品页面。

先复制淘口令到剪切板,

Write pictures described here

把剪切板中的内容粘贴到微信发给微信好友,

Write pictures described here

微信好友把淘口令复制到淘宝中,就可以打开好友分享的淘宝链接了。

Write pictures described here

4、 UIDocumentInteractionController

UIDocumentInteractionController主要是用来实现同设备上app之间的共享文档,以及文档预览、打印、发邮件和复制等功能。它的使用非常简单.

首先通过调用它唯一的类方法 interactionControllerWithURL:,并传入一个URL(NSURL),为你想要共享的文件来初始化一个实例对象。然后UIDocumentInteractionControllerDelegate,然后显示菜单和预览窗口。

Write pictures described here

效果如下,

Write pictures described here

5、 local socket

这种方式不太常见,也是很容易被iOS开发者所忽略但是特别实用的一种方法。它的原理很简单,一个App1在本地的端口port1234进行TCP的bind和listen,另外一个App2在同一个端口port1234发起TCP的connect连接,这样就可以建立正常的TCP连接,进行TCP通信了,那么就想传什么数据就可以传什么数据了。

这种方式最大的特点就是灵活,只要连接保持着,随时都可以传任何相传的数据,而且带宽足够大。它的缺点就是因为iOS系统在任意时刻只有一个app在前台运行,那么就要通信的另外一方具备在后台运行的权限,像导航或者音乐类app。

它是常用使用场景就是某个App1具有特殊的能力,比如能够跟硬件进行通信,在硬件上处理相关数据。而App2则没有这个能力,但是它能给App1提供相关的数据,这样APP2跟App1建立本地socket连接,传输数据到App1,然后App1在把数据传给硬件进行处理。

Write pictures described here

6、 AirDrop

通过AirDrop实现不同设备的App之间文档和数据的分享;

7、 UIActivityViewController

iOS SDK中封装好的类在App之间发送数据、分享数据和操作数据;

Write pictures described here

Write pictures described here

Write pictures described here

8、 App Groups

App App between Group for the same development team, including App between a reader and Extension share the same space, data sharing. Between multiple applications developed by the same team if they can directly share data, greatly improving the user experience.

Write pictures described here

Write pictures described here

Guess you like

Origin www.cnblogs.com/tangyuanby2/p/11323653.html