user1013448
user1013448

Reputation: 249

open text files with my ios app

I am trying to register my app as being able to open text files. Based on some digging, below is what I tried and while it compiled, it didnt work. When I go into dropbox and try to launch a txt file, I get 'No installed apps support opening this file'. What do I need to do to make my app show up for any txt file?

<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Text File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>txt</string>
<string>TXT</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.txt</string>
</array>
</dict>
</array>

Upvotes: 1

Views: 2949

Answers (2)

Cue
Cue

Reputation: 3092

Answer updated for iOS 11 and Xcode 9

If the document type you are adding is not a custom document type, you don't have to "register your app" because the standard types are already know by iOS (this is the case of text files).

Just select the target in your project and enter the text file type in the Document Types section:

enter image description here

For more info, please see the "Adding A Document Type" section of this Apple's document: https://developer.apple.com/library/content/qa/qa1587/_index.html

Upvotes: 1

FD_
FD_

Reputation: 12919

My app imports TXT files, too. Change your Info.plist:

  • Change public.txt in the listing above to com.myapp.txt (or whatever you want)
  • After the last </array> of your listing above add:

    <key>UTExportedTypeDeclarations</key>
    <array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>Plain Text Document</string>
        <key>UTTypeIdentifier</key>
        <string>com.myapp.txt</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>txt</string>
            <key>public.mime-type</key>
            <string>text/plain</string>
        </dict>
    </dict>
    </array>
    

You may replace com.myapp.txt with whatever identifier you want. I hope this helps.

Upvotes: 3

Related Questions