Launch an app from within another (iPhone)

后端 未结 14 1646
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 01:20

    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".

    Step 2

    In PageViewControllerExample app open .plist file and add this code

    LSApplicationQueriesSchemes
    
        myapp
    
    

    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
        }
    }
    

提交回复
热议问题