微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当应用程序关闭时,iOS 深层链接回调不起作用

如何解决当应用程序关闭时,iOS 深层链接回调不起作用

我在我的应用程序中使用深层链接,并在我的 SceneDelegate 中使用此代码转至视图控制器。

func scene(_ scene: UIScene,openURLContexts URLContexts: Set<UIOpenURLContext>) {
  for context in URLContexts {
    print("url: \(context.url.absoluteURL)")
    print("scheme: \(context.url.scheme ?? "")")
    print("host: \(context.url.host ?? "")")
    print("path: \(context.url.path)")
    print("query: \(context.url.query ?? "")")
    print("components: \(context.url.pathComponents)")
  }
    window?.rootViewController?.performSegue(withIdentifier: "splashToCreateNewPassword",sender: nil)
}

当应用程序已经在后台打开时,它工作得很好,但是当用户关闭应用程序时,它就不起作用了。它只是打开应用程序的第一个屏幕。

解决方法

您可以从这个委托 func scene(_ scene: UIScene,willConnectTo session: UISceneSession,options connectionOptions: UIScene.ConnectionOptions)

获取 URL
func scene(_ scene: UIScene,options connectionOptions: UIScene.ConnectionOptions) {
        if let userActivity = connectionOptions.userActivities.first {
            if let incomingURL = userActivity.webpageURL {
                window?.rootViewController?.performSegue(withIdentifier: "splashToCreateNewPassword",sender: nil)
            }
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。