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
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.TestApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>testApp.linking</string>
</array>
</dict>
</array>
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
You can only launch apps that have registered a URL scheme. Then just like you open the SMS app by using sms:, you'll be able to open the app using their URL scheme.
There is a very good example available in the docs called LaunchMe which demonstrates this.
LaunchMe sample code as of 6th Nov 2017.