iOS13:如果应用程序未运行,则不会打开通用链接



我们已经在应用程序中实现了通用链接的处理,我正在努力解决以下问题:

  • 当应用程序在后台运行时,通用链接将打开(工作正常(
  • 当在安装了iOS13的设备上运行时,只有当应用程序在后台运行时,打开通用链接才能正常工作。如果已终止,则在点击链接应用程序正在启动,但未调用此方法
application(continue userActivity:.., restorationHandler:..)

有什么想法吗?

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
}

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

它可以是URL:launchOptions[UIApplicationLaunchOptionsURLKey]

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

我要做的是添加有条件的场景代理支持。这样,您将在scene(_:willConnectTo:)中获得消息。好吧,这将是更多的工作,但你需要与iOS 13及更高版本中的原生场景支持同步,现在似乎是时候这样做了。

相关内容

  • 没有找到相关文章

最新更新