universal link not working properly in iOS 13

I am trying to handle open apps from universal link click.for ios 13 when i am clicking link opens app not called continue userActivity function. I also tried to get it in scene delegate willconnnect to delegate. But still not calling My code is below what is wrong?

-AppDelegate

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
       FirebaseApp.configure()
      // Override point for customization after application launch.
      IQKeyboardManager.shared.enable = true
      IQKeyboardManager.shared.goNext()
       navigationBarDefualtStyle()
      return true
  }


  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool{
  //first launch after install
        print("Continue User Activity called: ")
     UniversalLink.shared.handleUniversalLinkUrl(url)
     return true
  }


  func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool{
        print("Continue User Activity called: ")
     UniversalLink.shared.handleUniversalLinkUrl(url)
       return true
  }


   func application(_ application: UIApplication,continue userActivity: NSUserActivity,restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
     print("Continue User Activity called: ")
       if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
         guard let url = userActivity.webpageURL else { return false }
         UniversalLink.shared.handleUniversalLinkUrl(url)
    }
    return true
  }
  • SceneDelegate
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        guard let _ = (scene as? UIWindowScene) else { return }
       guard let url =  connectionOptions.urlContexts.first?.url else {return}
        UniversalLink.shared.handleUniversalLinkUrl(url)
    }
     func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
         // Called when a new scene session is being created.
         // Use this method to select a configuration to create the new scene with.
         return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
     }


     func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {

     }


   func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
       guard let url = userActivity.webpageURL else { return  }
     UniversalLink.shared.handleUniversalLinkUrl(url)
   }

   func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
         print("Continue User Activity called: ")
     guard let url =  URLContexts.first?.url else {return}
      UniversalLink.shared.handleUniversalLinkUrl(url)
   }
}
import UIKit
class UniversalLink {
    public static let shared = UniversalLink()
     private init(){}
     var window: UIWindow?
    let navigator = Navigator()
  func handleUniversalLinkUrl (_ url:URL) {

         guard let viewController = navigator.getDestination(for: url) else { return}
         window?.rootViewController = viewController
         window?.makeKeyAndVisible()

  }

}
 struct Navigator {
  func getDestination(for url: URL) -> UIViewController? {
      let storyboard = UIStoryboard(name: "Main", bundle: .main)
       var naviagteViewController = UIViewController()
      if url.lastPathComponent == "/digitom-confirm-email/" {
        getVerify(key: "", success: { (result) in
        naviagteViewController = storyboard.instantiateViewController(withIdentifier: "HomePageNavigtion") as? MainPage ?? UIViewController()
        }) { (message) in
        }

      return naviagteViewController


    }else if url.lastPathComponent == "/digitom-password-reset/confirm/" {
      guard let  resetPassword = storyboard.instantiateViewController(withIdentifier: "FP_ChangePasswordViewController") as? FP_ChangePasswordViewController else {return nil}
       return  resetPassword
    }else {
      return UIViewController()
    }

  }
}

No Comments Yet