I have two apps that communicate with each other via openUrl. I want to be able to check a couple things before opening the second app.
i.e. App1 wants to launch App2. So App2 checks to see if it can open the given URL. If it can, continue with the launch. If it CAN'T, stop the launch and show an error on App1.
It seems like iOS has this functionality already, but I can't figure out how to get it to work.
This is example code from App1 that would launch App2.
let url = URL(string: "APP2://Screen1")
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: { _ in })
} else {
self.showError("Couldn't Open App2")
}
This is example code for App2 that would try to accept the URL.
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
guard options[.sourceApplication] as? String == "com.test.app1" else { return false }
if self.canLogInFrom(url) {
return true
else {
return false
}
If I return false, it goes ahead with the launch anyways. It doesn't matter what I return in this function it launches App2 no matter what.
Is there a way in App2, that I can implement the AppDelegate CanOpenURL function?