I'm trying to import a ZIP file via the built-in 'Open With...' function.
Here's what I have added to my Info.plist file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>ZIP Archive</string>
<key>CFBundleTypeIconFile</key>
<string>zip</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>ZIP </string>
</array>
<key>CFBundleTypeExtensions</key>
<array>
<string>zip</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/zip</string>
<string>application/x-zip</string>
<string>application/x-zip-compressed</string>
</array>
</dict>
</array>
However, my app is not appearing when the 'Open With...' view is launched. Why is this?
Your problem is that you've failed to declare the relevant uniform type identifier (UTI). For many file types you need to either import or export a UTI; for zip files you needn't bother because it's on the list of UTIs that the system inherently recognises.
So it should be sufficient simply to add the following to your document type:
<key>LSItemContentTypes</key>
<array>
<string>com.pkware.zip-archive</string>
</array>
Expanding on #Tommy's answer you can add this value using Xcode in your project as shown:
Related
I want to associate a text-based custom file type with my app on iOS.
When I open a link to the file which is behind some php script, Safari shows the "open in" option with my app in it, which is OK.
However when I open a link which points directly to my file (running a web server for test purposes), Safari decides that it can read the file itself and displays the content by itself. Which is definitely not OK.
On the side note, if I substitute any binary file (zip, ...) and use my extension, file associating will still work.
The code in plist-info:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>320.png</string>
<string>64.png</string>
</array>
<key>CFBundleTypeName</key>
<string>My File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.Company.Product.ext</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.content</string>
<string>public.text</string>
<string>public.plain-text</string>
<string>public.utf16-plain-text</string>
<string>public.utf16-external-plain-text</string>
<string>public.utf8-plain-text</string>
</array>
<key>UTTypeDescription</key>
<string>My File</string>
<key>UTTypeIdentifier</key>
<string>com.Company.Product.ext</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>ext</string>
<key>public.mime-type</key>
<string>application/octet-stream</string>
</dict>
</dict>
</array>
My question is: how to persuade Safari to NOT open the file itself? It it even possible? Do I have to use some mime type other than "application/octet-stream"?
Define a custom MIME type (i.e. application/x-my.custom.type) for your files, and have PHP or your web server serve them. This should help.
I have successfully registered my app to open PDF files by including the following in my info.plist:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
</array>
However, I cannot seem to register my app to open any image files, I have tried to register not only for the base image UTI, but also specific types like png and jpg. Is it possible to register to open image files?
Bad news - cannot be done. Wish these things would be stated in the docs.
open plist with Source code and add this for document.
<dict>
<key>CFBundleTypeName</key>
<string>All Files</string>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
<string>public.content</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
i hope this usefull for you.
Open the plist with an editor...
Capitalization, etc is critical, recommend specifying both lower case and upper case file extensions.
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>jpg</string>
<string>JPG</string>
</array>
<key>CFBundleTypeName</key>
<string>Images</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
Then save the file. App should now be registered to handle this type of file.
I have an other problem with Xcode 4. I really like the new IDE but there are a few things I didn't get to work yet. One thing is to register Document Types with Xcode 4.
I tried it with the old way through the plist file, but it didn't work. (Means I couldn't open a file with my app) But I don't now how to set it up with the interface of Xcode 4.
My latest try looks like this: (Copied the entry made from Xcode in the info.plist)
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.plain-text</string>
</array>
<key>UTTypeDescription</key>
<string>Configuration File</string>
<key>UTTypeIdentifier</key>
<string>com.myname.projec.iws</string>
</dict>
</array>
and:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>AnIcon-320</string>
</array>
<key>CFBundleTypeName</key>
<string>Config File</string>
<key>LSItemContentTypes</key>
<array>
<string>com.myname.projec.iws</string>
</array>
</dict>
</array>
This does not work. The file in Mail doesn't have the option to open with my app.
Does anyone have a working example with Xcode 4 or a tutorial how to do it. I don't have any further Idea how to get it work.
Sandro
I think the role and the file extension are missing.
If you want to specify a file extension, you need to add UTTypeTagSpecification:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>my document type</string>
<key>UTTypeIdentifier</key>
<string>com.mycompany.myfiletypename</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>iws</string>
</array>
</dict>
</dict>
For the role, you need to add CFBundleTypeRole:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>My file</string>
<key>CFBundleTypeIconFiles</key>
<array>
<string>document-320.png</string>
<string>document-64.png</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>com.mycompany.myfiletypename</string>
</array>
</dict>
</array>
You can edit the equivalent of your 'com.mycompany.myfiletypename' by setting "Document Types" => "Item 0" => "Document OS Types" => "Item 0".
The default value is "????" which you can change to "com.mycompany.myfiletypename".
I think the other properties speak for themselves.
I just looked at my old .plist file and cut and pasted the keys and values into the new one in Xcode 4 project that had been imported from an Xcode3 version. It apparently "loses" some of the info in the .plist for UTI's when it comes over. However, when I pasted the missing keys/values back in from .plist made with Xcode3, the new values worked AND they appear in the GUI so you can now "browse" the GUI and see what goes where. Kind of reverse engineering the GUI but it works.
In an iPhone application I am dealing with files that have a double extension like *.my.txt
Thanks to tips found here, I've successfully associated *.txt with my app, but am unable to associate my.txt with :
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>com.site.my.txt</string>
<key>UTTypeDescription</key>
<string>My Text File Type</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>my.txt</string>
<key>public.mime-type</key>
<string>application/mytxt</string>
</dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
</dict>
</array>
I don't have control over the extension unfortunately.
I don't want *.txt to open in my app, only those with the extension *.my.txt
Would anyone have any tips for me?
By definition, the file extension is everything after the last period in the filename. So the extension of your files is txt and not my.txt. What you want will not work.
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"?
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>
Check out /var/mobile/Library/Preferences/com.apple.LaunchServices.plist.