ios文件预览以及使用其他应用打开文件

来源:互联网 发布:2017金英杰免费网络课 编辑:程序博客网 时间:2024/04/30 20:04

iOS提供技术显示您的应用程序不直接支持文件的预览。的iOS还提供了文件类型关联一个系统的注册表,使您的应用程序来处理来自其他安装的应用程序文件的打开。这些强大的技术,包括UIKit框架的UIDocumentInteractionController类,在UIDocumentInteractionController类参考说明,和快速查找框架,在为iOS快速Look框架参考。


注册您支持的文件类型


如果你的应用程序可以打开特定的文件类型,你可以在你的Xcode项目的Info.plist文件中注册该功能。当另一个应用程序请求系统的帮助打开这些类型的项目,您的申请将被包括在选项菜单呈现给用户。



如果你的程序是能够打开特定类型的文件,你应该注册到系统的支持。这使得其他应用程序,通过iOS的文件交互技术,向用户提供这些文件手头宽裕到您的应用程序的选项。


要声明其文件类型的支持,您的应用程序必须在其Info.plistproperty列表文件的CFBundleDocumentTypes关键。 (见的Core Foundation键),系统会将此信息到其他应用程序可以通过文档交互控制器访问注册表。

该CFBundleDocumentTypes密钥包含字典的数组,每个标识关于特定文件类型的信息。文档类型通常有一对一的对应于一个特定的文件类型。但是,如果你的应用程序会将多个文件类型以同样的方式,你可以组合这些文件类型一起被你的应用程序视为一个单一的文件类型。例如,如果你有你的应用程序的本地文档类型的旧的和新的文件格式,你可以组中的两个一起在一个单一的文件类型条目。以此方式,旧的和新的文件似乎是同一文档的类型和将要处理的方式相同。


在CFBundleDocumentTypes阵列中的每个字典可以包括下列键:


CFBundleTypeName指定文档类型的名称。
CFBundleTypeIconFiles是文件名的图像的资源,作为文档的图标的阵列。
LSItemContentTypes包含与代表该组中的支持的文件类型的UTI类型字符串数组。
LSHandlerRank描述本申请是否拥有该文档类型或仅仅是能够将其打开。

从应用程序的角度来看,一个文件是文件类型(或文件类型),该应用程序支持和治疗为一体。例如,图像处理应用程序可能处理不同的图像文件格式作为不同的文件类型,以便它可以微调与每一个相关联的行为。相反,一个字处理应用程序可能不关心底层的图像格式,只是管理使用一个单一的文件类型的所有图像格式。


清单1显示了能够打开一个自定义文件类型的应用程序的Info.plist的一个示例XML片段。所述LSItemContentTypes键标识与文件格式和CFBundleTypeIconFiles键指向图标资源显示时,它使用相关的部分。

<dict>
   <key>CFBundleTypeName</key>
   <string>My File Format</string>
   <key>CFBundleTypeIconFiles</key>
       <array>
           <string>MySmallIcon.png</string>
           <string>MyLargeIcon.png</string>
       </array>
   <key>LSItemContentTypes</key>
       <array>
           <string>com.example.myformat</string>
       </array>
   <key>LSHandlerRank</key>
   <string>Owner</string>
</dict>
想了解更多info关键字,请点击 Information Property List Key Reference.


列表1  Core Foundation keys 

Key

Xcode name

Summary

Platforms

CFAppleHelpAnchor

“Help file”

The bundle’s initial HTML help file. See CFAppleHelpAnchorfor details.

OS X

CFBundleAllowMixedLocalizations

“Localized resources can be mixed”

Used by Foundation tools to retrieve localized resources from frameworks. See CFBundleAllowMixedLocalizations for details.

iOS, OS X

CFBundleDevelopmentRegion

“Localization native development region”

(Recommended) The default language and region for the bundle, as a language ID. See CFBundleDevelopmentRegionfor details.

iOS, OS X

CFBundleDisplayName

“Bundle display name”

(Recommended, Localizable) The actual name of the bundle. See CFBundleDisplayName for details.

iOS, OS X

CFBundleDocumentTypes

“Document types”

An array of dictionaries describing the document types supported by the bundle. See CFBundleDocumentTypes for details.

iOS, OS X

CFBundleExecutable

“Executable file”

(Recommended) Name of the bundle’s executable file. See CFBundleExecutable for details.

iOS, OS X

CFBundleHelpBookFolder

“Help Book directory name”

The name of the folder containing the bundle’s help files. See CFBundleHelpBookFolder for details.

OS X

CFBundleHelpBookName

“Help Book identifier”

The name of the help file to display when Help Viewer is launched for the bundle. See CFBundleHelpBookName for details.

OS X

CFBundleIconFile

“Icon file”

A legacy way to specify the app’s icon. Use the CFBundleIcons or CFBundleIconFiles keys instead. See CFBundleIconFile for details.

iOS, OS X

CFBundleIconFiles

“Icon files”

A top-level key for specifying the file names of the bundle’s icon image files. See CFBundleIconFiles for details.

See also CFBundleIcons as an alternative to this key.

iOS 3.2 and later

CFBundleIcons

None 

File names of the bundle’s icon image files. See CFBundleIconFiles for details.

iOS 5.0 and later

CFBundleIdentifier

“Bundle identifier”

(Recommended) An identifier string that specifies the app type of the bundle. The string should be in reverse DNS format using only the Roman alphabet in upper and lower case (A–Z, a–z), the dot (“.”), and the hyphen (“-”). See CFBundleIdentifier for details.

iOS, OS X

CFBundleInfoDictionaryVersion

“InfoDictionary version”

(Recommended) Version information for the Info.plistformat. See CFBundleInfoDictionaryVersion for details.

iOS, OS X

CFBundleLocalizations

“Localizations”

Contains localization information for an app that handles its own localized resources. See CFBundleLocalizations for details.

iOS, OS X

CFBundleName

“Bundle name”

(Recommended, Localizable) The short display name of the bundle. See CFBundleName for details.

iOS, OS X

CFBundlePackageType

“Bundle OS Type code”

The four-letter code identifying the bundle type. See CFBundlePackageType for details.

iOS, OS X

CFBundleShortVersionString

“Bundle versions string, short”

(Localizable) The release-version-number string for the bundle. See CFBundleShortVersionString for details.

iOS, OS X

CFBundleSignature

“Bundle creator OS Type code”

The four-letter code identifying the bundle creator. See CFBundleSignature for details.

iOS, OS X

CFBundleSpokenName

"Accessibility bundle name” 

The spoken name of the app. See CFBundleSpokenName for details.

iOS, OS X

CFBundleURLTypes

“URL types”

An array of dictionaries describing the URL schemes supported by the bundle. See CFBundleURLTypes for details.

iOS, OS X

CFBundleVersion

“Bundle version”

(Recommended) The build-version-number string for the bundle. See CFBundleVersion for details.

iOS, OS X

CFPlugInDynamicRegistration

“Plug-in should be registered dynamically”

If YES, register the plug-in dynamically; otherwise, register it statically. See CFPlugInDynamicRegistration for details.

OS X

CFPlugInDynamicRegistrationFunction

Plug-in dynamic registration function name”

The name of the custom, dynamic registration function. See CFPlugInDynamicRegisterFunction for details.

OS X

CFPlugInFactories

“Plug-in factory interfaces”

For static registration, this dictionary contains a list of UUIDs with matching function names. See CFPlugInFactories for details.

OS X

CFPlugInTypes

“Plug-in types”

For static registration, the list of UUIDs CFPlugInTypes for details.

OS X

CFPlugInUnloadFunction

“Plug-in unload function name”

The name of the custom function to call when it’s time to unload the plug-in code from memory. See CFPlugInUnloadFunction for details.

OS x

二,从其他应用程序打开文件


该系统可能会要求您的应用程序打开特定文件,并将其呈现给用户。这通常是因为另一个应用程序遇到您注册支持一种类型的文件。在这种情况下,该系统提供了您的应用程序使用的URL文件,将您的应用推到前台。
该系统可能会要求您的应用程序打开特定文件,并将其呈现给用户。这通常是由于另一个应用中遇到的文件,并用一个文档交互控制器来处理它。您收到有关在应用程序中打开该文件的信息:willFinishLaunchingWithOptions:或应用:didFinishLaunchingWithOptions:您的应用程序委托的方法。如果您的应用程序处理自定义文件类型,则必须实现此委托方法(而不是applicationDidFinishLaunching方法),并用它来初始化您的应用程序。


选项字典传递给应用程序:willFinishLaunchingWithOptions:或应用:didFinishLaunchingWithOptions:方法中包含要打开该文件的信息。具体来说,您的应用程序应该在看这本字典下列键:
UIApplicationLaunchOptionsURLKey包含一个NSURL对象,指定要打开的文件。
UIApplicationLaunchOptionsSourceApplicationKey包含与发起打开请求的应用程序的束标识符一个NSString。
UIApplicationLaunchOptionsAnnotationKey包含属性列表对象的源应用程序要与文件相关联在打开时。
如果UIApplicationLaunchOptionsURLKey项存在,您的应用程序必须打开该密钥引用的文件,并立即提交其内容。您可以使用其他键在字典中,以收集有关周围文件的打开情况的信息。
三,显示和打印快速查找预览


为了获得更多的控制权的文件预览,可以直接使用快速查找框架。您可以选择动画呈现预览时使用的风格,并可以预览的项目列表,以及单个项目。快速浏览预览控制器还提供了内置的AirPrint打印支持的文件类型。
为了获得更多的控制权的文件预览,可以直接使用快速查找框架。该框架的主要类是QLPreviewController。它依赖于委托用于响应预览操作,并在一个数据源,用于提供预览项。


在iOS 4.2的,后来,通过快速查找预览控制器提出了专门的视图包括动作按钮打印选项。如果控制器能够提供文件的预览,它也可以打印。没有打印代码为你写。


要显示快速查看预览控制器,可以使用其中任一选项:


将其推入视图使用一个UINavigationController对象。
目前它有模式,全屏,使用presentModalViewController:动画:它的父类的UIViewController方法。
目前文档交互控制器(如预览和打开文件描述,用户可以通过选择快速查找从文档交互控制器的选项菜单,然后调用快速查看预览控制器。
当自己呈现快速查找预览控制器,选择最适合您的应用程序的可视化和导航样式的显示选项。莫代尔,全屏显示可能的工作最好的,如果你的应用程序不使用导航栏。如果你的应用程序使用iPhone式的导航,你可能想选择你推到预览视图。


所显示的预览包括从项目URL的最后一个路径组件采取了冠军。您可以通过实施previewItemTitleaccessor的预览项覆盖。


快速浏览预览器可以显示预览用于以下项目:


iWork的文件
Microsoft Office文档(after office97 )
富文本格式(RTF)文件
PDF文件
图片
文本文件的统一类型标识符(UTI)符合public.text类型(见统一类型标识符参考)
逗号分隔值(CSV)文件

要使用快速查看预览控制器,则必须提供使用QLPreviewControllerDataSource协议参考描述的方法的数据源对象。该数据源提供的预览项所述控制器,并告诉它多少项目在预览导航列表以包括。如果在列表中有多个项目,一模态,呈现(即,全屏)控制器显示导航箭头,让项目中的用户切换。对于使用导航控制器推快速查看预览控制器,可以提供导航栏按钮,通过预览项列表移动。


对于快速查看框架的完整描述,请参阅快速查找框架参考Quick Look Framework Reference for iOS

本文翻译自:https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010409-SW1

0 0
原创粉丝点击