简体   繁体   中英

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>

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.

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:

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM