By Jeff


2009-01-07 03:41:47 8 Comments

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 and launch right into the Phone app (close the current app, open the Phone app).

would this be possible? I know this can be done for making phone calls with the tel URL link, but I want to instead just have the Phone app launch without dialing any specific number.

13 comments

@iOS 2018-07-19 08:04:28

In Swift 4.1 and Xcode 9.4.1

I have two apps 1)PageViewControllerExample and 2)DelegateExample. Now i want to open DelegateExample app with PageViewControllerExample app. When i click open button in PageViewControllerExample, DelegateExample app will be opened.

For this we need to make some changes in .plist files for both the apps.

Step 1

In DelegateExample app open .plist file and add URL Types and URL Schemes. Here we need to add our required name like "myapp".

enter image description here

Step 2

In PageViewControllerExample app open .plist file and add this code

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>myapp</string>
</array>

Now we can open DelegateExample app when we click button in PageViewControllerExample.

//In PageViewControllerExample create IBAction
@IBAction func openapp(_ sender: UIButton) {

    let customURL = URL(string: "myapp://")
    if UIApplication.shared.canOpenURL(customURL!) {

        //let systemVersion = UIDevice.current.systemVersion//Get OS version
        //if Double(systemVersion)! >= 10.0 {//10 or above versions
            //print(systemVersion)
            //UIApplication.shared.open(customURL!, options: [:], completionHandler: nil)
        //} else {
            //UIApplication.shared.openURL(customURL!)
        //}

        //OR

        if #available(iOS 10.0, *) {
            UIApplication.shared.open(customURL!, options: [:], completionHandler: nil)
        } else {
            UIApplication.shared.openURL(customURL!)
        }
    } else {
         //Print alert here
    }
}

@lostInTransit 2009-01-07 11:43:10

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.

@Eenvincible 2017-11-04 10:01:49

Would you help by sharing a URL for the docs?

@lostInTransit 2017-11-06 10:21:35

Updated answer. Hope that helps

@Eenvincible 2017-11-06 10:23:01

Thanks; by any chance, do you belong in the iOS Developer Family chatrooms?

@Alok 2017-07-19 11:09:11

To achieve this we need to add few line of Code in both App

App A: Which you want to open from another App.

App B: From App B you want to open App A

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&registered=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

@choofie 2017-05-25 08:07:13

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.

enter image description here

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)

enter image description here

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.

@cdescours 2017-05-03 12:34:57

Swift 3 quick and paste version of @villy393 answer for :

if UIApplication.shared.canOpenURL(openURL) {
    UIApplication.shared.openURL(openURL)
} else if UIApplication.shared.canOpenURL(installUrl) 
    UIApplication.shared.openURL(installUrl)
}

@Gordon Wilson 2009-01-07 05:35:38

As Kevin points out, URL Schemes are the only way to communicate between apps. So, no, it's not possible to launch arbitrary apps.

But, it is possible to launch any app that registers a URL Scheme, whether its Apple's, yours, or another developer's. The docs are here:

Communicating with Other Applications

As for launching the phone, looks like your tel: link needs to have least three digits before the phone will launch. So you can't just drop into the app w/o dialing a number.

@Willster 2011-02-01 13:42:13

You can check whether the application in question is installed by using UIApplication's - (BOOL)canOpenURL:(NSURL *)url

@eggie5 2011-07-26 04:13:26

what happens if 2 apps register the same url handler and then the url is called? I know in Android you will be presented w/ a list so you can choose which of the two you want to run. How does ios handle this?

@Futur 2011-11-30 14:04:55

Note: If more than one third-party app registers to handle the same URL scheme, there is currently no process for determining which app will be given that scheme. Ref: developer.apple.com/library/ios/#documentation/iPhone/…

@Grimxn 2016-10-25 10:34:00

Please update the link. The given one no longer exists...

@Sindri Jóelsson 2018-06-06 13:51:07

This is the updated link which mentions the note about more-than one third party app registering to handle the same URL-scheme: Apple Docs

@villy393 2016-01-19 13:30:50

In Swift

Just incase someone was looking for a quick Swift copy and paste

if let url = NSURL(string: "app://") where UIApplication.sharedApplication().canOpenURL(url) {
            UIApplication.sharedApplication().openURL(url)
} else if let itunesUrl = NSURL(string: "https://itunes.apple.com/itunes-link-to-app") where UIApplication.sharedApplication().canOpenURL(itunesUrl) {
            UIApplication.sharedApplication().openURL(itunesUrl)      
}

@KIO 2015-11-17 17:35:31

The lee answer is absolutely correct for iOS prior to 8.

In iOS 9 you must whitelist any URL schemes your App wants to query in Info.plist under the LSApplicationQueriesSchemes key (an array of strings):

enter image description here

@Gustavo Barbosa 2016-12-23 17:01:27

The best answer should be a merge between @KIO and villy393

@lee 2014-06-04 09:31:42

I found that it's easy to write an app that can open another app.

Let's assume that we have two apps called FirstApp and SecondApp. When we open the FirstApp, we want to be able to open the SecondApp by clicking a button. The solution to do this is:

  1. In SecondApp

    Go to the plist file of SecondApp and you need to add a URL Schemes with a string iOSDevTips(of course you can write another string.it's up to you).

enter image description here

2 . In FirstApp

Create a button with the below action:

- (void)buttonPressed:(UIButton *)button
{
  NSString *customURL = @"iOSDevTips://";

  if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
  {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
  }
  else
  {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"URL error"
                              message:[NSString stringWithFormat:@"No custom URL defined for %@", customURL]
                              delegate:self cancelButtonTitle:@"Ok" 
                              otherButtonTitles:nil];
    [alert show];
  }

}

That's it. Now when you can click the button in the FirstApp it should open the SecondApp.

@youssman 2014-11-07 17:36:27

You can see the full explanation here iosdevelopertips.com/cocoa/…

@srinivas n 2015-08-24 07:22:03

@Lee I am following your post , safari can open the application but another app not open (button pressed method ) else block is executed , what is the problem can you please help me

@lee 2015-08-24 08:10:13

Please give me more some detail of your problem

@user1872384 2015-11-04 08:41:58

@srinivas n I believe you need to replace @"iOSDevTips://"; with @"iOSDevTips://location?id=1"];

@user5936834 2016-11-04 18:33:54

People who can't get this to work, add a array of strings named 'LSApplicationQueriesSchemes' in Info.plist of the FirstApp. Then add the schemes that your app want to open, in this case the Item 0 would be iOSDevTips

@John Erck 2017-01-12 17:23:08

See also KIO's answer below (stackoverflow.com/a/33763449/394969). FirstApp needs to add LSApplicationQueriesSchemes to its Info.plist to be able to open SecondApp.

@Apurva 2017-03-21 13:01:12

Nice answer, now how to get bundle id of First App in Second App?

@Sekhar 2017-08-22 17:28:34

Hi. My App name has a space in between. How do I write it? if the other app name is my developer tips.? how do i create an url?

@btmanikandan 2014-09-04 13:54:52

Try the following code will help you to Launch an application from your application

Note: Replace the name fantacy with actual application name

NSString *mystr=[[NSString alloc] initWithFormat:@"fantacy://location?id=1"];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];

@Foebe 2011-12-26 22:03:43

I also tried this a while ago (Launch iPhone Application with Identifier), but there definitely is no DOCUMENTED way to do this. :)

@Moszi 2012-05-31 07:50:36

It is documented... Check the Apple documentation. developer.apple.com/library/IOs/#documentation/iPhone/…

@Foebe 2012-06-01 14:02:22

I know that URL schemes are possible, but what I asked in my question and what Jeff asked, is how to open Apps that do not support url schemes...

@Nickolas 2011-12-26 11:04:24

Here is a good tutorial for launching application from within another app:
iOS SDK: Working with URL Schemes
And, it is not possible to launch arbitrary application, but the native applications which registered the URL Schemes.

@Lily Ballard 2009-01-07 04:59:54

No it's not. Besides the documented URL handlers, there's no way to communicate with/launch another app.

Related Questions

Sponsored Content

22 Answered Questions

[SOLVED] How to link to apps on the app store

47 Answered Questions

[SOLVED] Vertically align text to top within a UILabel

13 Answered Questions

[SOLVED] How to launch safari and open URL from iOS app

  • 2012-09-14 00:01:31
  • Dale Dietrich
  • 189534 View
  • 194 Score
  • 13 Answer
  • Tags:   ios url mobile-safari

5 Answered Questions

[SOLVED] Is it possible to launch another app in iOS 8 using Swift?

  • 2014-07-14 02:38:14
  • Grant Chen
  • 10637 View
  • 9 Score
  • 5 Answer
  • Tags:   ios swift ios8

0 Answered Questions

Launch an app from within another without scheme(iOS)

  • 2017-10-30 06:27:06
  • Kuroiteiken
  • 160 View
  • 0 Score
  • 0 Answer
  • Tags:   ios objective-c

3 Answered Questions

[SOLVED] launching two app in iphone sdk?

10 Answered Questions

[SOLVED] How to check if an app is installed from a web-page on an iPhone?

1 Answered Questions

[SOLVED] Cannot Launch an app from within another (iPhone)

  • 2016-09-16 10:03:50
  • virat
  • 282 View
  • 2 Score
  • 1 Answer
  • Tags:   ios objective-c

12 Answered Questions

2 Answered Questions

[SOLVED] Is it possible to launch an iPhone app from a text message?

  • 2010-10-23 01:51:19
  • MusiGenesis
  • 1656 View
  • 3 Score
  • 2 Answer
  • Tags:   iphone

Sponsored Content