I'd like to open iChangi app and FlightRadar24 programatically in swift. Anyone can help me please. Thanks in advance.
Asked
Active
Viewed 303 times
-2
-
Try to check: https://stackoverflow.com/questions/419119/launch-an-app-from-within-another-iphone – πter Jan 22 '21 at 08:13
-
Yes, the other app (FlightAware) can open like that by that app name, for those 2 can not. – Kyaw Htet Jan 22 '21 at 08:16
-
Either the other app you are trying to open is not configured in a way that is can be opened from another app (URL scheme is not configured), or the url you are using is not correct. – πter Jan 22 '21 at 08:22
-
`if UIApplication.shared.canOpenURL(url){ UIApplication.shared.open(url, options: [:], completionHandler: nil) }else{}` In above code, canOpenURL return true and run the below line, but app is not actually launch. – Kyaw Htet Jan 22 '21 at 08:28
-
URL scheme is not the same name as app ? It can be diff? How can I see the url schema of the apps. Thanks – Kyaw Htet Jan 22 '21 at 08:31
-
Could you please share the whole code where you are trying to open the app ? – πter Jan 22 '21 at 08:39
-
`alert.addAction(UIAlertAction(title: "iChangi", style: .default) { _ in guard let url = URL(string: "ichangi://") else { return } if UIApplication.shared.canOpenURL(url){ UIApplication.shared.open(url, options: [:], completionHandler: nil) }else{ UIApplication.shared.open(URL(string: "https://www.changiairport.com")!, options: [:], completionHandler: nil) } })` please check @πter – Kyaw Htet Jan 22 '21 at 08:45
-
Your code seems to be right. Is the application installed on your device/simulator you are trying to open on ? – πter Jan 22 '21 at 08:58
-
sure @πter, application is already installed on my device and .canOpenURL is return true, and reach to open statement. Only application is not launch. So I doubt the schema I added in .plist. it might wrong. But no idea which one should I add in .plist. Currently I use the same as app name "iChangi". Thanks. – Kyaw Htet Jan 22 '21 at 10:25
-
As I mentioned, it can happen that a custom url scheme(https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app) is not set for the apps you are trying to open – πter Jan 22 '21 at 12:01
1 Answers
0
You will need to grab the CFBundleURLSchemes that the target app uses.
For iChangi its "ichangi2"
For FlightRadar24 its "fr24"
You then need to add the url schemes into your plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>ichangi2</string>
<string>fr24</string>
</array>
And then in your code you can check to see if the app is installed and launch the app or take user to website:
guard let url = URL(string: "ichangi2://") else { return }
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.open(URL(string: "https://www.changiairport.com/")!, options: [:], completionHandler: nil)
}

valosip
- 3,167
- 1
- 14
- 26