How to communicate other installed ios apps & pass text
// SENDER SIDE
-(IBAction) openReceiverApp:(id)sender {
// Opens the Receiver app if installed, otherwise displays an error
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *str= @”Pass text to receiver App” ;
NSString *URLEncodedText = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *ourPath = [@”ReceiverAppText://” stringByAppendingString:URLEncodedText];
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
else {
//Display error
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”Receiver Not Found” message:@”The Receiver App is not installed. It must be installed to send text.” delegate:nil cancelButtonTitle:@”OK” otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
// RECEIVER SIDE
In the Project Navigator, expand the Supporting Files group and open the Receiver-Info.plist file.
You can add a new row by going to the menu and clicking Editor > Add Item. Set up a URL Types item by adding a new item. Expand the URL Types key, expand Item 0, and add a new item, “URL schemes”. Fill in “ReceiverAppText” for Item 0 of “URL schemes” and your company identifier for the “URL Identifier”.
& to catch the text from sender app, you have to implement a provided method of ios,
- (
BOOL
)application:(
UIApplication
*)application
handleOpenURL
:(
NSURL
*)url {
// Display text
UIAlertView
*alertView;
NSString
*text = [[url
host
]
stringByReplacingPercentEscapesUsingEncoding
:NSUTF
8
StringEncoding];
alertView = [[
UIAlertView
alloc
]
initWithTitle
:
@"Text"
message
:text
delegate
:nil
cancelButtonTitle
:
@"OK"
otherButtonTitles
:nil
];
[alertView
show
];
[alertView
release
];
return
YES
;
}