Launch an app from within another (iPhone)

后端 未结 14 1668
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 01:14

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

相关标签:
14条回答
  • 2020-11-22 01:35

    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)
    }
    
    0 讨论(0)
  • 2020-11-22 01:36

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

    0 讨论(0)
  • 2020-11-22 01:37

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

    0 讨论(0)
  • 2020-11-22 01:38

    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.

    0 讨论(0)
  • 2020-11-22 01:39

    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 it's Apple's, yours, or another developer's. The docs are here:

    Defining a Custom URL Scheme for Your App

    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 without dialing a number.

    0 讨论(0)
  • 2020-11-22 01:40

    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.

    0 讨论(0)
提交回复
热议问题