Adding "Open In..." option to iOS app
Asked Answered
S

4

49

On iOS devices, the Mail app offers "Open In..." option for attachments. The apps listed have registered their CFBundleDocumentTypes with the OS. What I am wondering is how my app might allow users to open files generated by my app in other apps. Is Mail the only app that provides this feature?

Sarver answered 20/10, 2010 at 18:44 Comment(2)
The updated article that provides the relevant information can now be found under Document Interaction Programming Topics.Proptosis
I'm pretty sure the answer is here: #2774843.Phantasmagoria
M
38

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.

Morpheus answered 20/10, 2010 at 19:58 Comment(4)
Thanks! That looks like exactly what I was searching for. And, yes, my app creates .csv and .zip files.Sarver
you might want to edit your answer to reference new link (Apple has reorganized iOS Reference Library, apparently).Sarver
I added the document type in my app. for eg i have added type PDF . But when i running the document interaction it just taking the quick look application.Mulcahy
Is there any way to make my app show up first? When the sheet comes up, it suggests a bunch of apps like AirDrop, Kindle, Messages, Slack etc first -- which can't even open my custom file type -- and then the option to open with my app is all the way at the bottom of the list.Handed
M
23

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;
}
Mantel answered 19/8, 2013 at 20:17 Comment(1)
After following this, Its still not working for me. I have posted the question here.Mingmingche
W
6

In order to be visible in the list of "open in..." for all files, you need to add this to your plist

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Open All Files</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
           <string>public.content</string>
           <string>public.data</string>
        </array>
    </dict>
</array>

Once your app shows in "open in...", you need to load that file. Most website shows to implement this function:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool
{
   println("Open URL "+url.path!)
}

But this function that worked fine in IOS 7 crashes in IOS 8. I had to implement the following function instead to get it to work.

func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool 
{
   println("Open URL "+url.path!)
}
Wive answered 14/10, 2014 at 1:12 Comment(0)
S
2

I add my app in "open in" list successfully as follows,

Select info in YourAppName.target Add a new document type filter, which Name is anything you want and the type is defined in https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1

Hope you can be success too!!

However, the feature I want to implement is "Share" like Facebook or Slack do, I can not make it still...anyone can give me a big hand :(

Spindry answered 15/2, 2016 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.