Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating custom UTI for use with airdrop, iOS

Tags:

ios

airdrop

uti

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

like image 562
ZiEiTiA Avatar asked Jul 17 '17 22:07

ZiEiTiA


1 Answers

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.

like image 127
rmaddy Avatar answered Sep 22 '22 12:09

rmaddy