-1

We have implemented handling of universal links in our app and I am struggling with the following issues:

  • Universal Links opens when the app is running in the background (working fine)
  • When running on the device with iOS13 installed, opening a universal link only works properly if the app is running in the background. If it has been terminated, after tapping the link the app is getting launched but this method not called
application(continue userActivity:.., restorationHandler:..)

Any ideas?

var window: UIWindow?   
var tabBarController1: UITabBarController?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
{
    presentAppLaunchVC()
    return true
}

func presentVC(navController : UINavigationController)
{
    if var topController = UIApplication.shared.keyWindow?.rootViewController {
        while let presentedViewController = topController.presentedViewController {
            topController = presentedViewController
        }
        topController.present(navController, animated: false, completion: nil)
    }
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    

    if userActivity.activityType == NSUserActivityTypeBrowsingWeb
    {
        guard let url = userActivity.webpageURL else {
            return false
        }
        if !isValidDeepLink(web_url: url)
        {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
        else
        {
            scrapDeepLinkingUrl(url : url)
        }
    }
    return true
}
func isValidDeepLink(web_url :URL) -> Bool
{
    
    guard let components = URLComponents(url : web_url,resolvingAgainstBaseURL : true) else {
        return  false
    }
    guard let host = components.host else {
        return false
    }
    switch host {
    case "www.domain.com":
        return true
    default:
        return false
    }
}
func scrapDeepLinkingUrl(url : URL)
{
    }
    else
    {
        presentAppLaunchVC()
    }
}
func presentAppLaunchVC()
{
    let storyBoard = UIStoryboard(name: storyboard_name, bundle: nil)
    let screen = storyBoard.instantiateViewController(withIdentifier: identifier)
    if identifier == "dashboardVC" {
        tabBarController1 = screen as? UITabBarController
    }
    self.window?.rootViewController = screen
}
        
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
Danish Farooq
  • 135
  • 1
  • 10

2 Answers2

0

You need to check the URL in didFinishLaunchingWithOptions method as well.

It can be an URL: launchOptions[UIApplicationLaunchOptionsURLKey]

or it can be an Universal link: launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey]

BoygeniusDexter
  • 2,154
  • 1
  • 16
  • 14
0

What I would do is add conditional scene delegate support. That way, you would get the message in scene(_:willConnectTo:). Okay, this is going to be more work, but you need to get in sync with the native scene support in iOS 13 and later, and this seems to be the moment to do so.

matt
  • 515,959
  • 87
  • 875
  • 1,141