4

I am trying to associate a custom file that my app creates (it's XML) so that users can email the files to each other. I have followed the excellent tutorial here:

How do I associate file types with an iPhone application?

The file is named XXX.checklist

But it's not associating. I believe my problem is with the public.mime-type key as I have no idea what I am supposed to put there. Below is the associated info-plist entries

<key>CFBundleDocumentTypes</key>
<array>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>docIcon64.png</string>
                <string>docIcon320.png</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>My App Checklist</string>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>LSHandlerRank</key>
            <string>Owner</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.mycompany.appid.checklist</string>
            </array>
        </dict>
    </array>
</array>

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.content</string>/// i tried public.text but it allowed the file to be opened by the devices default text viewer which I would not like. 
        </array>
        <key>UTTypeDescription</key>
        <string>My App Checklist</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.appid.checklist</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key> // fixed this key
            <string>checklist</string>
            <key>public.mime-type</key>
            <string>text/xml</string> /// changed to this, still doest work though
        </dict>
    </dict>
</array>
Community
  • 1
  • 1
Brodie
  • 3,526
  • 8
  • 42
  • 61
  • I have implement above soluion. but i am uable to see my app on share menu. can u provide me exact answer for that – Hitu Bansal Jun 22 '15 at 08:15

1 Answers1

7

If your UTI is declared as public.data I assume that your checklist file is a custom binary data.

You should then simply use application/octet-stream as a mime-type.

UPDATE: Got it, your problem is more trivial than anyone would expect. One more thing for starters - public.data is okay for all its descendants (including public.xml), so for an XML file you can set any of these:

  • public.item
  • public.data
  • public.content
  • public.text
  • public.xml

The list of applications offered to open your file type is build based on known apps in system that can handle given UTI plus yours. Since the default text editor opens public.text and public.xml it will be the default action for your kind of files (your application will show up on the list invoked by a long press on a mail attachment).

There is (apparently) no applications that handle public.data (the same for public.content), so when you use this UTI, the default action for an attachment would be to open it in your app.

Now to the point... your CFBundleDocumentTypes has one extra <array> level:

<key>CFBundleDocumentTypes</key>
<array>
    <array>     <!-- remove this line -->
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>docIcon64.png</string>
                <string>docIcon320.png</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>My App Checklist</string>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>LSHandlerRank</key>
            <string>Owner</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.mycompany.appid.checklist</string>
            </array>
        </dict>
    </array>     <!-- and this line -->
</array>

And it's gonna work. The UTExportedTypeDeclarations part is already fine.

ayoy
  • 3,835
  • 19
  • 20
  • the file is just a text XML file. I put public.data because that is what was in one of the tutorials I saw – Brodie Feb 28 '12 at 14:19
  • edited my code above to reflect from what I learned from your answer. It still doesn't work though – Brodie Feb 28 '12 at 14:43
  • Wow, good catch. Yes it works now, thank you. Thanks also for the explanation as I actually understand what I'm doing now. I did notice that the icon in the email app did not display, it was just a blank square. I assume there's nothing special about defining the doc icons other than what I did above? – Brodie Feb 28 '12 at 22:15
  • You're welcome, glad I could help. As for the icon, your definition is alright, the icon might appear for the second time or so. It was missing in my app for the first time as well. Or try and change folder in mail and go back to your message with attachment, it may help as well. – ayoy Feb 28 '12 at 22:20
  • Do you need both `CFBundleDocumentTypes` and `UTExportedTypeDeclarations` keys to lanch an app through a file of a custom file extension? – Lealo Oct 27 '17 at 15:32