Registering the File Types Your App Supports

了解如何在iOS应用中注册支持特定文件类型的元数据,以便其他应用可通过文档交互技术将这些文件转交给您的应用。

Registering the File Types Your App Supports

If your app is capable of opening specific types of files, you should register that support with the system. This allows other apps, through the iOS document interaction technology, to offer the user the option to hand off those files to your app.

To declare its support for file types, your app must include the CFBundleDocumentTypes key in its Info.plistproperty list file. (See “Core Foundation Keys”.) The system adds this information to a registry that other apps can access through a document interaction controller.

The CFBundleDocumentTypes key contains an array of dictionaries, each of which identifies information about a specific document type. A document type usually has a one-to-one correspondence with a particular file type. However, if your app treats more than one file type the same way, you can group those file types together to be treated by your app as a single document type. For example, if you have an old and new file format for your application’s native document type, you could group both together in a single document type entry. This way, old and new files would appear to be the same document type and would be treated the same way.

Each dictionary in the CFBundleDocumentTypes array can include the following keys:

  • 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.

  • LSHandlerRank describes whether this application owns the document type or is merely able to open it.

From your app’s perspective, a document is a file type (or file types) that the application supports and treats as a single entity. For example, an image processing application might treat different image file formats as different document types so that it can fine tune the behavior associated with each one. Conversely, a word processing application might not care about the underlying image formats and just manage all image formats using a single document type.

Listing 1 shows a sample XML snippet from the Info.plist of an app capable of opening a custom file type. The LSItemContentTypes key identifies the UTI associated with the file format and the CFBundleTypeIconFiles key points to the icon resources to use when displaying it.

Listing 1  Document type information for a custom file format

<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>

For more information about the contents of the CFBundleDocumentTypes key, see the description of that key in Information Property List Key Reference.

From: http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html%23//apple_ref/doc/uid/TP40010411-SW1


Example:

<key>CFBundleDocumentTypes</key>
        <array>
                <dict>
                        <key>CFBundleTypeName</key>
                        <string>PDF</string>
                        <key>LSHandlerRank</key>
                        <string>Alternate</string>
                        <key>LSItemContentTypes</key>
                        <array>
                                <string>com.adobe.pdf</string>
                        </array>
                </dict>
                <dict>
                        <key>CFBundleTypeName</key>
                        <string>TEXT</string>
                        <key>LSHandlerRank</key>
                        <string>Alternate</string>
..




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值