iphonesharepasteboard

data share between two iphone apps


i want to share text data between two iphone apps. How can i use paste board for this purpose. Can anyone help me with a sample code. Thanks in advance. Suggest me if there are better ways than pasteboard to accomplish my task.


Solution

  • If you simply want to use IPC, make both of your apps recognize some URL scheme. Then call

    [[UIApplication sharedApplication] openURL:
      [NSURL URLWithString:@"theOtherApp://dataToShare"]];
    

    to send, and use -application:handleOpenURL: to receive.


    To share strings via the pasteboard, use

     UIPasteboard* board = [UIPasteboard generalPasteboard];
     board.string = @"Some string to share";
    

    to save, and use board.string as a getter to retrieve the string to share. But if the user copy anything in between your shared data will be lost.


    Alternatively, you can share stuff via: