Adding “Open In…” option to iOS app

Take a look at the Document Interaction Programming Topics for iOS: Registering the File Types Your App Supports.

As long as you provide your document types in your Info.plist, other apps that recognize that document type will list your app in their “open in” choices. Of course, that presumes that your app creates documents that other apps can open.

This is a great tutorial, that helped me.

I have added support for *.xdxf files in my app. In short, you have to do two things. First – add entries like this to your app’s Plist file:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>XDXF Document</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.alwawee.xdxf</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeDescription</key>
        <string>XDXF - XML Dictionary eXchange Format</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.text</string>
        </array>
        <key>UTTypeIdentifier</key>
        <string>com.alwawee.xdxf</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>xdxf</string>
            <key>public.mime-type</key>
            <string>text/xml</string>
        </dict>
    </dict>
</array>

Here, you should add UTExportedTypeDeclarations only if your file type is unique. Or by other words is not here.

Second – handle delegate method in AppDelegate:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{

    if (url != nil && [url isFileURL]) {

        //  xdxf file type handling

        if ([[url pathExtension] isEqualToString:@"xdxf"]) {

            NSLog(@"URL:%@", [url absoluteString]);

        }

    }

    return YES;
}

Leave a Comment