创建用于空投,iOS的自定义UTI [英] Creating custom UTI for use with airdrop, iOS

查看:419
本文介绍了创建用于空投,iOS的自定义UTI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的info.plist中使用此代码:

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?

此处

推荐答案

如果您的应用定义了新的文件类型.那么您需要在Info.plistUTExportedTypeDeclarations部分中定义该自定义UTI.

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

这可以在Xcode上的应用程序目标"的信息"选项卡上的已导出的UTI"部分下进行设置,也可以如下所示手动更新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.

CFBundleDocumentTypes是用来声明您的应用可以打开的文件类型.

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

这是一个伪造的文件类型,恰好是扩展名为.fun的二进制文件.

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>

安装该文件后,您还可以设置CFBundleDocumentTypes,以便您可以选择打开这样的文件来应用:

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>

请注意CFBundleDocumentTypesLSItemContentTypes值必须与UTI的UTTypeIdentifier匹配.

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

这篇关于创建用于空投,iOS的自定义UTI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆