How to Associate File Types With an Iphone Application

How do I associate file types with an iPhone application?

File type handling is new with iPhone OS 3.2, and is different than the already-existing custom URL schemes. You can register your application to handle particular document types, and any application that uses a document controller can hand off processing of these documents to your own application.

For example, my application Molecules (for which the source code is available) handles the .pdb and .pdb.gz file types, if received via email or in another supported application.

To register support, you will need to have something like the following in your Info.plist:

<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>Document-molecules-320.png</string>
<string>Document-molecules-64.png</string>
</array>
<key>CFBundleTypeName</key>
<string>Molecules Structure File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.sunsetlakesoftware.molecules.pdb</string>
<string>org.gnu.gnu-zip-archive</string>
</array>
</dict>
</array>

Two images are provided that will be used as icons for the supported types in Mail and other applications capable of showing documents. The LSItemContentTypes key lets you provide an array of Uniform Type Identifiers (UTIs) that your application can open. For a list of system-defined UTIs, see Apple's Uniform Type Identifiers Reference. Even more detail on UTIs can be found in Apple's Uniform Type Identifiers Overview. Those guides reside in the Mac developer center, because this capability has been ported across from the Mac.

One of the UTIs used in the above example was system-defined, but the other was an application-specific UTI. The application-specific UTI will need to be exported so that other applications on the system can be made aware of it. To do this, you would add a section to your Info.plist like the following:

<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.plain-text</string>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>Molecules Structure File</string>
<key>UTTypeIdentifier</key>
<string>com.sunsetlakesoftware.molecules.pdb</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>pdb</string>
<key>public.mime-type</key>
<string>chemical/x-pdb</string>
</dict>
</dict>
</array>

This particular example exports the com.sunsetlakesoftware.molecules.pdb UTI with the .pdb file extension, corresponding to the MIME type chemical/x-pdb.

With this in place, your application will be able to handle documents attached to emails or from other applications on the system. In Mail, you can tap-and-hold to bring up a list of applications that can open a particular attachment.

When the attachment is opened, your application will be started and you will need to handle the processing of this file in your -application:didFinishLaunchingWithOptions: application delegate method. It appears that files loaded in this manner from Mail are copied into your application's Documents directory under a subdirectory corresponding to what email box they arrived in. You can get the URL for this file within the application delegate method using code like the following:

NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];

Note that this is the same approach we used for handling custom URL schemes. You can separate the file URLs from others by using code like the following:

if ([url isFileURL])
{
// Handle file being passed in
}
else
{
// Handle custom URL scheme
}

How to associate file type .x_t with iOS App?

Use UTI as com.you.x-t and file extension as x_t.

<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
</array>
<key>CFBundleTypeName</key>
<string>x_t file</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.you.x-t</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.item</string>
</array>
<key>UTTypeDescription</key>
<string>x_t files</string>
<key>UTTypeIdentifier</key>
<string>com.you.x-t</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>x_t</string>
</dict>
</dict>
</array>

UTI: com.you.x_t & file extension x_t does not work

UTI: com.you.x-t & file extension x-t does not work

associate file types with iOS application in swift

try this. i copy and pasted ur code in my plist and its not working. then i created another plist and its code is as below. and its working

       <key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>LSItemContentTypes</key>
<array>
<string>com.pryvateBeta.crypt.pvt</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeName</key>
<string>pvt file</string>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeIdentifier</key>
<string>com.pryvateBeta.crypt.pvt</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.mime-type</key>
<string>application/pry</string>
<key>public.filename-extension</key>
<string>pvt</string>
</dict>
</dict>
</array>

How do I register a custom filetype in iOS

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>

IOS file association - default app to open certain file

You have to associate you app with the file types you want it to open.
You do this by adding some parameters to your Info.plist.

This post explains it:
How do I associate file types with an iPhone application?

Associate a File Type with my iOS App: No Image for file

in Xcode 5, select your "TARGET", go to tab "INFO", Have a look in "Document Types" : Did you set your icon here ? Now, check if in exported / imported UTI you set the identifiers = the Type you put in "Document Types".

especially check :

com.mycomp.document.kmk != com.mycomp.document.kpk

edit : (removed)

edit 2 :

Based on apple doc here

you should set Exported UTIs :

identifier = com.mycomp.document.kmk

conform to = public.data

Additional exported UTI properties

UTTypeTagSpecification (Dictionary)

  public.mime-type = Application/XXX    (replace XXX vita your app name)
public.filename-extension = kmk (extension without the dot)

you'll found that in your info.plist at UTExportedTypeDeclarations

<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>YOUR DESCRIPTION</string> (to be changed)
<key>UTTypeIdentifier</key>
<string>com.mycomp.document.kmk</string>
<key>UTTypeSize320IconFile</key>
<string>Icon@2x</string>
<key>UTTypeSize64IconFile</key>
<string>Icon</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>kmk</string>
<key>public.mime-type</key>
<string>Application/YOUR-APP-NAME</string> (to be changed)
</dict>
</dict>
</array>

Edit 3 :

netshark1000 have report that Application/YOUR-APP-NAME have solve the issue.

Hop this can help others.



Related Topics



Leave a reply



Submit