19

I am currently creating a app in which i want to let the user backup their files (plist + m4a). I zip the files and change the extension to a custom one (specifically for my app, say "*.MyBackup"). The user can then either export via email or with iTunes file sharing.

I have already read about CFBundleDocumentTypes but didn't really get what I had to do with them.

The part where i am currently stuck at is how to associate my extension with my app. If the user sends himself an email with the "custom"-zip file he's supposed to be able to open it with my app.

How do I do this and what are "UTExportedTypeDeclarations"?

JNK
  • 1,753
  • 8
  • 25
  • 37
  • possible duplicate of [How do I associate file types with an iPhone application?](http://stackoverflow.com/questions/2774343/how-do-i-associate-file-types-with-an-iphone-application) – Brad Larson Nov 15 '10 at 17:28

2 Answers2

36

I hope it's okay if I dump in that part of my projects info.plist without much further explanation. I think it's pretty much self-explanatory.

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>Icon-iPad-doc320.png</string>
            <string>Icon-iPad-doc.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MyAppName File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <!-- my app supports files with my custom extension (see UTExportedTypeDeclarations) -->
            <string>com.myurl.myapp.myextension</string>
            <!-- and csv files. -->
            <string>public.comma-separated-values-text</string>
        </array>
    </dict>
</array>



<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>MyAppName File</string>
        <key>UTTypeIdentifier</key>
        <string>com.myurl.myapp.myextension</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>myextension</string>
            <key>public.mime-type</key>
            <string>application/octet-stream</string>
        </dict>
    </dict>
</array>
Fuad All
  • 871
  • 11
  • 13
Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
  • ahhh... ok :D stil a complete n00b :D – JNK Nov 15 '10 at 16:55
  • 3
    I also provide a little more explanation of what these sections do in my answer here: http://stackoverflow.com/questions/2774343/how-do-i-associate-file-types-with-an-iphone-application/2781290#2781290 – Brad Larson Nov 15 '10 at 17:29
  • 1
    I'm trying to email a .csv file to my phone for an app that's registered for the above public.comma-separated-values-text UTI, but the mail app on the phone won't list my app as one of the potential recipients. Any idea why? (re stackoverflow etiquette, is it OK to pose this question here?) – hkatz May 30 '11 at 13:49
2

Check out /var/mobile/Library/Preferences/com.apple.LaunchServices.plist.

Vukašin Manojlović
  • 3,717
  • 3
  • 19
  • 31
Chuen
  • 21
  • 1