iOS Apps间分享数据

来源:互联网 发布:有关网络得现代诗歌 编辑:程序博客网 时间:2024/05/21 15:03

iOS Apps间分享数据

请参考:

  • iOS应用程序间共享数据
  • Tutorial: Sharing Data Locally Between iOS Apps

总的来说有如下几种:

  • UIDocumentInteractionController
  • UIActivityViewController
  • Shared Keychain Access
  • Custom URL Scheme
  • Web Service
  • UIPasteboard + URL Scheme

UIDocumentInteractionController

请参考:

  • iOS关于使用其他应用打开本应用文档
  • UIDocumentInteractionController之程序间文档共享

UIDocumentInteractionController文档见Document Interaction Programming Topics for iOS

注册APP支持的文件类型(Registering the File Types Your App Supports)
在Info.plist中使用CFBundleDocumentTypes键,对应的为array,可以包括如下的key:

  • CFBundleTypeName specifies the name of the document type(文件类型).
  • CFBundleTypeIconFiles is an array of filenames for the image resources to use as the document’s icon(图标).
  • LSItemContentTypes contains an array of strings with the UTI types that represent the supported file types in this group(UTI数组).
  • LSHandlerRank describes whether this application owns the document type or is merely able to open it(是否拥有or仅仅是打开).

UTI类型请参考:System-Declared Uniform Type Identifiers

打开支持的文件类型(Opening Supported File Types)
The system may ask your application to open a specific file and present it to the user. This typically occurs because another application encountered the file and used a document interaction controller to handle it. You receive information about the file to be opened in the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method of your application delegate. If your application handles custom file types, you must implement this delegate method (instead of the applicationDidFinishLaunching: method) and use it to initialize your application.

The options dictionary passed to the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method contains information about the file to be opened. Specifically, your application should look in this dictionary for the following keys:

  • UIApplicationLaunchOptionsURLKey contains an NSURL object that specifies the file to open.
  • UIApplicationLaunchOptionsSourceApplicationKey contains an NSString with the bundle identifier of the application that initiated the open request.
  • UIApplicationLaunchOptionsAnnotationKey contains a property list object that the source application wanted to associate with the file when it was opened.
    If the UIApplicationLaunchOptionsURLKey key is present, your application must open the file referenced by that key and present its contents immediately. You can use the other keys in the dictionary to gather information about the circumstances surrounding the opening of the file.

保存共享的文件
请参考:

  • Save file opened with UIDocumentInteractionController
  • Import file from another application using UIDocumentInteractionController

参考

  • Importing & Exporting Documents in iOS
  • Importing Data via Custom File Types in iOS
  • Why is my iOS app not showing up in other apps’ “Open in” dialog?列有常见的配置信息
  • How do I associate file types with an iPhone application?
0 0
原创粉丝点击