Search code examples
iosuiimagensdatadata-transfer

Move data/images between two iOS apps using custom URL handler


After googling around and searching SO for a while, I stil couldn't find an answer -

I've wondered, How could I transfer data between two of my apps using custom URL handlers? Specifically images or an NSData object for that matter.

I know about being able to open specific parts of my app using custom handlers such as myapp1://start , myapp2://start , but I'm not sure how to go on transferring large amounts of data (~80k) through these handlers.

Would love to hear any creative solutions :)

p.s. The solution should be iOS >= 4.3 Compatible


Solution

  • Use the custom URL handlers in combination with UIPasteboard. Save something from your first app (say, an image) to the general pasteboard, like so:

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    [[UIPasteboard generalPasteboard] setImage:myImage];
    

    Then use the custom URL schemes to switch apps.

    Then retrieve your image from within the new app when you need it:

       UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
       UIImage *tempImg = pasteboard.image;
    

    Battle-tested. ; )