Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I transfer files from one application to another in the same iOS device?

I am writing an iOS application that performs conversion of a file saved by another application on the same device to another format. How can I transfer files from one application to another in the same device? Note that the files are non-textual files.

like image 760
Lopper Avatar asked Aug 12 '11 02:08

Lopper


2 Answers

UIDocumentInteractionController is your friend.

Basically it works like this:

  1. App 1 registers as being able to handle files of type XYZ
  2. App 2 implements UIDocumentInteractionController and will give users the options to "send the file to App1" (I believe this has to be user activated)
  3. App 1 implements -(BOOL)application:openURL:sourceApplication:annotation: and deals with the transferred file which will be saved in your Documents/Inbox directory. From there you can copy the file elsewhere and then manipulated it, making sure you clean up by getting rid of the original one saved on the Inbox folder.

Class reference available here

Document interaction programming guide available here

like image 175
Rog Avatar answered Sep 26 '22 00:09

Rog


If you are developing both apps, you can store shared information in the keychain as long as your bundle identifiers conform to the same bundle seed id. See here for more info. Of course, if you are making both applications, you can use a URL scheme to pass in base64 encoded data as well.

Update: As rog said below, UIDocumentInteractionController is great, but it is only available for 4.2 and up, so you are cutting out a major portion of your users if you want to use it.

like image 39
coneybeare Avatar answered Sep 26 '22 00:09

coneybeare