【问题标题】:ASWebAuthenticationSession on macOS 12.4 do not work properlymacOS 12.4 上的 ASWebAuthenticationSession 无法正常工作
【发布时间】:2022-08-02 18:47:51
【问题描述】:

我正在为我的应用程序使用 ASWebAuthenticationSession 授权。 在 macOS12.4 之前可以正常工作,但是会出现 unresponse\'s 问题。 \"session.start success\"后,点击取消或继续,没有任何反应。

        var session = ASWebAuthenticationSession.init(url: url, callbackURLScheme: \"http\", completionHandler: completionHandler)

        guard let provider = NSApplication.shared.keyWindow!.contentViewController as? FlutterViewController else {
            result(FlutterError(code: \"FAILED\", message: \"Failed to aquire root FlutterViewController\" , details: nil))
            return
        }

        session.presentationContextProvider = provider

        if(!session.start()) {
            NSLog(\"session.start  fail\");
        } else {
            NSLog(\"session.start success\");
        }

    标签: flutter macos-monterey aswebauthenticationsession


    【解决方案1】:

    我注意到两件事对我来说似乎不正确。


    第一个是您需要为您的会话提供强有力的参考。此限制仅适用于 iOS 版本 < 13.0。

    这意味着,会话变量必须“比”它启动时调用的方法“寿命更长”,例如为整个班级设置会话属性。 我在您提供的代码 sn-p 中看不到类似的东西,对我来说它看起来像是一个作用域变量。

    来自苹果documentation for this feature

    对于部署目标早于 iOS 13 的 iOS 应用,您的应用 必须保持对会话的强引用,以防止系统 在等待身份验证完成时释放会话。


    第二件事是您的回调 URL 方案似乎设置为https。 该方案应与您的应用程序包 ID 匹配。 它必须在您的Info.plist 文件中进行配置。 Here's an example how to achieve this。它实际上应该是 com.company.myappname 而不是 http。您的身份验证提供程序还需要重定向到 com.company.myappname://someurl 才能完成这项工作。请注意:// 不能是回调 URL 方案的一部分,只能是之前的部分。

    【讨论】:

      猜你喜欢
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 2017-06-10
      • 2021-03-02
      • 2023-02-09
      相关资源
      最近更新 更多