场景委托不会更新视图控制器

时间:2020-05-02 03:35:40

标签: ios swift xcode

如何在Scene Delegate中实现此代码

  // App Delegate
 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return SCSDKLoginClient.application(app, open: url, options: options)
    }

因为我需要从回调中获取一些数据。目前,回调不会触发应用程序委托。假设回调是OAuth流。

我找到了解决方案,但效果不佳

// Scene Delegate
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        guard let url = URLContexts.first?.url else {
            return
        }

        SCSDKLoginClient.application(UIApplication.shared, open: url, options: nil)
     }

因为我需要将选项值传递给该场景。我该如何在Scene Delegate中实现AppDelegate方法?

1 个答案:

答案 0 :(得分:0)

如果问题是如何传递选项参数,请尝试以下代码。基本上UIOpenURLContext有两个成员变量 url options ,您必须映射该ApplicationDelegate选项。

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        guard let urlContext = URLContexts.first else {
            return
        }

        let url = urlContext.url

        let options: [UIApplication.OpenURLOptionsKey : Any] = [
            UIApplication.OpenURLOptionsKey.annotation : urlContext.options.annotation as Any,
            UIApplication.OpenURLOptionsKey.sourceApplication : urlContext.options.sourceApplication as Any,
          UIApplication.OpenURLOptionsKey.openInPlace : urlContext.options.openInPlace
        ]

        SCSDKLoginClient.application(
            UIApplication.shared,
            open: url,
            options: options)
    }

免责声明-我没有测试Snapchat代码,请尝试为您提供一个想法。