Search code examples
iphoneiosdropboxopen-with

iPhone - "Open In" in SDK?


The DropBox app lets you view a document in another app by selecting the Open In option.

We are building a document management app and need to be able to view the Word/Excel docs like Dropbox does, in another app.

Where in the SDK do I look so that I can pass a document to another app to open in that one?

Ian


Solution

  • You'll need to use the UIDocumentInteractionController class.

    It's available in UIKit, so you don't need a particular framework for this.

    You instantiate this class, using an URL to the file you want to pass to another application, which is able to handle the file type:

    UIDocumentInteractionController * controller;
    
    controller = [ UIDocumentInteractionController interactionControllerWithURL: someFileURL ];
    

    Then, you can present it:

    [ controller presentOpenInMenuFromRect: someRect inView: someView animated: YES ];
    

    Note that, on iPad, you'll need to retain the controller, otherwise it will be deallocated, making your application crash.

    This method returns a BOOL value. NO is returned if no application for the file type was found. In such a case, you may display an alert.