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
In order to let you open your application from another, you'll need to make changes in both applications. Here are the steps using Swift 3 with iOS 10 update:
1. Register your application that you want to open
Update the Info.plist
by defining your application's custom and unique URL Scheme.
Note that your scheme name should be unique, otherwise if you have another application with the same URL scheme name installed on your device, then this will be determined runtime which one gets opened.
2. Include the previous URL scheme in your main application
You'll need to specify the URL scheme you want the app to be able to use with the canOpenURL:
method of the UIApplication
class. So open the main application's Info.plist
and add the other application's URL scheme to LSApplicationQueriesSchemes
. (Introduced in iOS 9.0)
3. Implement the action that opens your application
Now everything is set up, so you're good to write your code in your main application that opens your other app. This should looks something like this:
let appURLScheme = "MyAppToOpen://"
guard let appURL = URL(string: appURLScheme) else {
return
}
if UIApplication.shared.canOpenURL(appURL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(appURL)
}
else {
UIApplication.shared.openURL(appURL)
}
}
else {
// Here you can handle the case when your other application cannot be opened for any reason.
}
Note that these changes requires a new release if you want your existing app (installed from AppStore) to open. If you want to open an application that you've already released to Apple AppStore, then you'll need to upload a new version first that includes your URL scheme registration.