Is it possible to launch any arbitrary iPhone application from within another app?, For example in my application if I want the user to push a button an
To achieve this we need to add few line of Code in both App
App A: Which you want to open from another App. (Source)
App B: From App B you want to open App A (Destination)
Code for App A
Add few tags into the Plist of App A Open Plist Source of App A and Past below XML
CFBundleURLTypes
CFBundleURLName
com.TestApp
CFBundleURLSchemes
testApp.linking
In App delegate of App A - Get Callback here
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// You we get the call back here when App B will try to Open
// sourceApplication will have the bundle ID of the App B
// [url query] will provide you the whole URL
// [url query] with the help of this you can also pass the value from App B and get that value here
}
Now coming to App B code -
If you just want to open App A without any input parameter
-(IBAction)openApp_A:(id)sender{
if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"testApp.linking://?"]]){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App is not available!" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
If you want to pass parameter from App B to App A then use below Code
-(IBAction)openApp_A:(id)sender{
if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"testApp.linking://?userName=abe®istered=1&Password=123abc"]]){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App is not available!" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
Note: You can also open App with just type testApp.linking://? on safari browser