continuing userActivity not working when app is closed

432 views Asked by At

I am trying to implement universal linking in swift, but am having an issue when the app is not already opened. It works perfectly fine when the app has been previously opened, it will navigate to the proper view controller. When the app has not been opened, it will not navigate to the desired view controller, I think it has something to do with the root view controller, but am not positive. Has anyone dealt with the same issues?

in AppDelegate

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        
        let navigator = Navigator()
        if let url = userActivity.webpageURL {
            navigator.getDesination(for: url)
        }
     }

the getDestination function will eventually trigger the following code eventually:

func openPostVC(id: Int, showComment: Bool, commentID: Int?) {
        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
            return }
        if let _ = appDelegate.window?.rootViewController as? BannedViewController { return }
        
        let postStoryboard = UIStoryboard.singlePost
        let singlePostVC = postStoryboard.instantiateInitialViewController() as! SinglePostViewController
        singlePostVC.shouldNavigateToHomeAction = {
            self.loadMainStoryboard()
        }
        
        let navigationVC = UINavigationController(rootViewController: singlePostVC)
        navigationVC.view.backgroundColor = .white
        
        appDelegate.window?.rootViewController = navigationVC
        appDelegate.window?.makeKeyAndVisible()
    }
0

There are 0 answers