0

I have defined a custom document type containing binary data for my app, with identifier "com.mycompany.gcp", using an Exported UTI. I am using this document type to exchange data with macOS and iOS versions of my app. After much trial and error, it is working reasonably well. However, I feel like I am missing a critical step.

When I export a file from my app, I create the file using FileManager.createFile(atPath:, contents:, attributes:). I create the file with my gcp extension, however I do not know how to specify the identifier type, specifically to set it to "com.mycompany.gcp". When I export the file, if I inspect it with mdls, kMDItemContentType = "dyn.ah62d4rv4ge80s25u", which I assume refers to a dynamic identifier, rather than my identifier.

My questions are: 1) is there a way to set the identifier when creating the file? I have tried the NSURL methods to set the identifier without success. 2) does this matter?

I feel like the answer the question 2 is yes. With iOS, if I email or airdrop the file, I can open it with my app. However, with iMessage, no action occurs when I tap on a sent file.

Here are the relevant keys from the Info.plist for the iOS version of my app:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>GCP File</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.gcp</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>GCP File</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.gcp</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>gcp</string>
            </array>
        </dict>
    </dict>
</array>
jbaraga
  • 656
  • 5
  • 16
  • My iOS app defines some custom file types and `mdls` of one of those files on my Mac shows the expected UTI for `kMDItemContentType`. And I do nothing special when creating one of the files. So you may have an issue with your exported UTIs. Update your question with the relevant sections of your Info.plist. Show the `CFBundleDocumentTypes` and `UTExportedTypeDeclarations` sections. – rmaddy May 27 '17 at 02:37
  • I must have something wrong with the UTI declaration then. Question updated with Info.plist sections. – jbaraga May 27 '17 at 10:50
  • That all looks fine. It matches what I have for one of my iOS apps. – rmaddy May 27 '17 at 14:26
  • I changed the extension to gcph, and now mdls shows the expected UTI for kMDItemContentType. I would guess the gcp extension is registered by another app, and my exported UTI does not override that. Unfortunately, even with the correct content type, the file does not open in my app from Messages on iOS, but it will open with my app from Messages on macOS. If I add public.text conformance to the exported UTI in iOS, the file will be actionable in Messages on iOS, but it opens with document viewer, not my app. – jbaraga May 28 '17 at 15:44

0 Answers0