在Swift 4.1和Xcode 9.4.1中
我有两个应用程序1)PageViewControllerExample和2)DelegateExample . 现在我想用PageViewControllerExample app打开DelegateExample应用程序 . 当我单击PageViewControllerExample中的打开按钮时,将打开DelegateExample应用程序 .
为此,我们需要对这两个应用程序的.plist文件进行一些更改 .
Step 1
在DelegateExample app中打开.plist文件并添加URL类型和URL方案 . 在这里,我们需要添加我们的必需名称,如“myapp” .
Step 2
在PageViewControllerExample app中打开.plist文件并添加此代码
LSApplicationQueriesSchemes
myapp
现在,当我们点击PageViewControllerExample中的按钮时,我们可以打开DelegateExample应用程序 .
//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
}
}