Creating custom UTI for use with airdrop, iOS

匿名 (未验证) 提交于 2019-12-03 01:36:02

问题:

I am using this code in my info.plist:

<key>CFBundleDocumentTypes</key> <array>     <dict>         <key>CFBundleTypeName</key>         <string>AirDrop Profile File Type</string>         <key>LSHandlerRank</key>         <string>Default</string>         <key>LSItemContentTypes</key>         <array>             <string>com.apple.customProfileUTI.customprofile</string>         </array>     </dict> </array>

to declare a custom file type, going by the answer here, and have looked at the linked sample code, but couldn't follow it very well. I have a structure that I am converting to data and then sharing with airdrop, and I am trying to understand how to create a data type such that the receiving device knows to open my app to receive the data.

Can anyone clear it up a bit for me?

Answer is followed up here

回答1:

If your app defines a new file type. then you need to define that custom UTI in the UTExportedTypeDeclarations section of Info.plist.

This can be setup in Xcode on the Info tab of your app target under the Exported UTIs section or you can manually update Info.plist as shown below.

The CFBundleDocumentTypes is to declare what file types your app can open.

Here's a made up file type that happens to be a binary file with an extension of .fun.

<key>UTExportedTypeDeclarations</key> <array>     <dict>         <key>UTTypeConformsTo</key>         <array>             <string>public.data</string>         </array>         <key>UTTypeDescription</key>         <string>My Custom Binary File</string>         <key>UTTypeIdentifier</key>         <string>com.mycompany.myapp.myfiletype</string>         <key>UTTypeTagSpecification</key>         <dict>             <key>public.filename-extension</key>             <array>                 <string>fun</string>             </array>         </dict>     </dict> </array>

With that in place, you can also setup your CFBundleDocumentTypes so your app is offered as a choice to open such files:

<key>CFBundleDocumentTypes</key> <array>     <dict>         <key>CFBundleTypeIconFiles</key>         <array/>         <key>CFBundleTypeName</key>         <string>My Custom Binary File</string>         <key>LSHandlerRank</key>         <string>Owner</string>         <key>LSItemContentTypes</key>         <array>             <string>com.mycompany.myapp.myfiletype</string>         </array>     </dict> </array>

Note how the LSItemContentTypes value of CFBundleDocumentTypes must match the UTI's UTTypeIdentifier.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!