I'm trying to open a secondary view controller (not initial) in one app from a different app I built. So I'm trying to deep link to a view controller that's not the initial one, but the function is not being called at all.
I already implemented openURLContexts
:
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts)
}
Not being called:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print(url)
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true)
let host = urlComponents?.host ?? ""
print(host)
if host == "accessPage" {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "jsonVC") as? JSONViewController
window?.rootViewController = vc
}
return true
}
I added all the info.plist
stuff and made sure willFinishLaunchingWithOptions
and didFinishLaunchingWithOptions
both return true.
Whenever I open the second app from the first one the primary view controller is always the one being displayed, not the one I want which is the JSONViewController
.
Here's the code from the first app:
import UIKit
class ViewController: UIViewController {
@IBAction func accessButtonPressed(_ sender: UIButton) {
let application = UIApplication.shared
let secondAppPath = "second://accessPage"
guard let appURL = URL(string: secondAppPath) else { return }
if application.canOpenURL(appURL) {
application.open(appURL, options: [:], completionHandler: nil)
}
}
}
Commented out the SceneDelegate
file and deleted ApplicationSceneManifest
in the info.plist
, restarted Xcode and it worked just fine.