0

would appreciate any help. 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? Appreciate!

enter code here

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
}
        
4

2 回答 2

0

您还需要检查didFinishLaunchingWithOptions方法中的 URL。

它可以是一个 URL: launchOptions[UIApplicationLaunchOptionsURLKey]

或者它可以是通用链接: launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey]

于 2021-04-19T08:14:50.703 回答
0

我要做的是添加条件场景委托支持。这样,您将在scene(_:willConnectTo:). 好的,这将是更多的工作,但您需要与 iOS 13 及更高版本中的原生场景支持保持同步,这似乎是这样做的时候。

于 2021-04-19T23:19:26.737 回答