Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

iOS - Download file & launch with default app?

(Titanium newbie, so apologies if I've missed something obvious)

Is there a mechanism by which I can pass iOS a local file path, and have (whatever app is appropiate) open that file?

EDIT #2: I managed to hack together a very rough draft which does work @ http://pastie.org/1352776

Note that the picker doesn't properly launch and it has other problems, but it does actually launch.

EDIT: Browsing the iOS docs, I see that the proper way to do this is via a document interaction controller - http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/PreviewingandOpeningItems.html#//apple_ref/doc/uid/TP40010410-SW1

But I'm still stuck as to what titanium calls this functionality, or how to trigger it!


I'm trying to create a test app which
1) downloads a file [this works fine, using a modified kitchen sink example]
2) launches that file with whatever iOS thinks should run the file (ie: the PDF viewer for PDF, whatever it uses for ppt's, gallery for images, etc)

I had (perhaps naively) hoped I could just pass openURL the downloaded file and that it would magically work, but it silently fails.

Can someone point me in the right direction? The goal is something like dropbox - ie it stores several files, which you can then click to open in whatever app should open that file.

Thanks for any pointers anyone can give.


— asked December 5th 2010 by William G
  • filesystem
  • ios
  • mobile
  • This is related: http://developer.appcelerator.com/question/79891/where-is-createdocumentviewer-documented

    — commented December 5th 2010 by William G
  • yes and there still in no response… I have tried twitter, google and nothing yet

    — commented December 5th 2010 by Aaron Saunders
  • @Aaron Saunders - you're right, your twitter posting was what got me this far actually.. I hadn't thought to ping you directly!

    — commented December 6th 2010 by William G

4 Answers

  • Can't you just embed a webview and set the url to the local path?

    — answered December 6th 2010 by Sj Singh
    1 Comment
    • Not really.. while this may work in some circumstances, quick view doesn't pass the file to the app in the same way that a documentinteractioncontroller does, which is to actually hand over the file and launch the handler app.

      — commented December 6th 2010 by William G
  • here is a sample I wrote which should solve the problem for you


    — answered December 6th 2010 by Aaron Saunders
    1 Comment
    • Unfortunately, this solution only embeds the content in a webview. If you take a look at http://developer.apple.com/library/ios/#samplecode/DocInteraction/Listings/Classes_DITableViewController_m.html#//apple_ref/doc/uid/DTS40010052-Classes_DITableViewController_m-DontLinkElementID_4, you'll see the difference in how this functionality is presented (on long press) vs just putting the content in a webview.

      — commented December 6th 2010 by William G
  • William,

    I'm curious to know if you ever got this working properly. I started with you demo code no matter what I try I still get the weird invisible dialog behavior.


    — answered January 9th 2011 by E Telford
    1 Comment
    • Hi Erik,

      I'm afraid that I didn't progress this further because we managed to avoid needing it in the end.

      What I'd learned after this post was that TI's implementation of the document viewer is a little shaky, but that by editing the TI code and building your own custom TI, you could use some of the code examples from the apple site to create your own custom doc viewer.

      The big gotcha is that apple seem to enforce that the user must tap on an object to launch the uidocumentcontroller.. in other words, no app is allowed to simply launch it, the user has to tap something which is bound to the doccontroller.

      Sorry I couldn't be of more help.


      — commented January 17th 2011 by William G
  • I'm also looking to do this. Has anyone built a module that works in this fashion? Im surprised this doesn't exist yet. Perhaps my searching skills are lacking. Doug? :)

    — answered August 4th 2011 by Dave F
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.