ios - 深度链接仅在应用程序运行时有效

标签 ios swift deep-linking

我有一个应用程序,当用户与另一个用户共享应用程序中的特定内容时,它使用深层链接导航到某个页面。这在第二个用户已经运行应用程序时有效,但如果应用程序未运行,它只是打开应用程序并保留在主屏幕上。我知道我一定在这里遗漏了一些非常简单的东西,但我就是想不通,也无法在谷歌上找到与此相关的任何答案。

我在 AppDelegate.swift 中的代码:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        let urlPath : String = url.path as String!
        let urlHost : String = url.host as String!
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

        if(urlHost != "example.com")
        {
            print("Call Not From Correct Host. Not Continuing...")
            return false
        }

        if(urlPath == "/articles"){

            let article: ArticleDetailsViewController = mainStoryboard.instantiateViewController(withIdentifier: "ArticleDetailsViewController") as! ArticleDetailsViewController
            self.window?.rootViewController = article
        } 
        self.window?.makeKeyAndVisible()
        return true
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        return true
    }

最佳答案

这是正确的行为。 你应该在 appliction(_: didFinishLaunchingWithOptions:)

中处理它
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    if let url = launchOptions[.url] as? URL, let annotation = launchOptions[.annotation] {
        return self.application(application, open: url, sourceApplication: launchOptions[.sourceApplication] as? String, annotation: annotation)
    }
    return true
}

关于ios - 深度链接仅在应用程序运行时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44529289/

相关文章:

iphone - 使用缩进级别在 ios 中的 UITableview 中下拉

swift - 没有这样的模块 'SwiftyDropbox'

react-native - Facebook AppLinkData fetchDeferredApplinkData ReactNative

ios - 应用程序 openURL 在 didFinishLaunchingWithOptions 之后几秒钟被调用

javascript - 我如何知道某个应用程序是否已通过 Safari 安装在 iPhone 上

android - 如何在 flutter 中处理后退时的切换页面逻辑

iphone - 在类方法中访问全局声明的 NSArray 值时出错

python - 我一直在 Swift 中使用一个函数,它有一个很好的 Return Closure

swift - 有没有办法在没有任何实例化对象的情况下获取类的属性列表?

声明多个域时的 Android applink 消歧对话框