MacOS上的AswebauthenticationSession 12.4无法正常工作

发布于 2025-02-12 06:34:33 字数 906 浏览 1 评论 0原文

我正在为我的应用程序使用Aswebauthenticationsessessionsession。 它在MACOS12.4之前正常工作,但出现了无反应的问题。 在“ session.start成功”之后,单击取消或继续,没有响应。

        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");
        }

I'm using ASWebAuthenticationSession authorization for my application.
It works fine before macOS12.4, but occur unresponse's issue.
After "session.start success", Click Cancel or Continue and there is no response.

The window that can't be closed

        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");
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2025-02-19 06:34:34

编辑:我只是注意到我没有正确阅读,而错过了这个问题是MacOS而不是iOS的事实。我仍然希望其中一个答案可能会导致解决方案。

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


第一个是您的会议需要大量参考。此限制仅适用于iOS版本< 13.0。

这意味着,会话变量必须“超越”其启动的调用方法,例如为整个类设置会话属性。
在您提供的代码段中,我看不到类似的内容,对我来说看起来像是一个范围的变量。

从苹果此功能的文档

对于比iOS 13更早的iOS应用程序,您的应用程序
必须坚定地参考会议,以防止系统
在等待身份验证完成时处理会话。


第二件事是您的回调URL方案似乎设置为https
该方案应匹配您的应用程序包ID。
它必须在您的info.plist文件中配置。 这是一个示例,这是一个示例。它实际上应该是com.com.pan.myappname而不是http。您的身份验证提供商还需要重定向到com.com.com.pany.myappname:// someurl才能使此工作。请注意,://不得成为回调URL方案的一部分,仅是在此之前的零件。

Edit: I just noticed I did not read correctly and missed the fact that this question was for macOS, not iOS. I still hope one of those answers might lead to a solution.

I have noticed 2 things that seem incorrect to me.


The first one is that you need a strong reference for your session. This limitation is only valid for iOS version < 13.0.

This means, the session variable must "outlive" the invoked method it was started in, e.g. setting a session attribute for the whole class.
I cannot see something similar in the code snippet you provided, it looks like a scoped variable to me.

From Apples documentation for this feature:

For iOS apps with a deployment target earlier than iOS 13, your app
must keep a strong reference to the session to prevent the system from
deallocating the session while waiting for authentication to complete.


The second thing is your callback URL scheme seems to be set to https.
The scheme should match your apps bundle ID.
It must be configured in your Info.plist file. Here's an example how to achieve this. It should actually be something like com.company.myappname instead of http. Your authentication provider would also need to redirect to com.company.myappname://someurl to make this work. Please note the :// must not be part of the callback URL scheme, only the part before that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文