【问题标题】:How can I logout in my SFSafariViewController如何在我的 SFSafariViewController 中注销
【发布时间】:2022-01-06 21:50:01
【问题描述】:

我制作了登录 SFSafariViewController 的应用程序。登录时效果很好。但是在我注销后,如果我再次尝试登录,我已经登录了。这是因为我的自动登录信息存储在 SFSafariViewController 中。我试图删除缓存和cookie,但它不起作用。 :(

这是我的登录代码。

func requestCode() {
        let scope = "user"
        let urlString = "https://github.com/login/oauth/authorize?client_id=\(clientId)&scope=\(scope)"
        guard let url = URL(string: urlString) else {
            return
        }
        
    URLCache.shared.removeAllCachedResponses()

    if let cookies = HTTPCookieStorage.shared.cookies {
        for cookie in cookies {
            HTTPCookieStorage.shared.deleteCookie(cookie)
        }
    }
    
    let safariViewController = SFSafariViewController(url: url)
    safariViewController.delegate = self
    safariViewController.modalPresentationStyle = .automatic
    
    if let topViewController = UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }).flatMap({ $0.windows }).first(where: { $0.isKeyWindow }) {
        topViewController.rootViewController?.present(safariViewController, animated: true, completion: nil)
    }
}

【问题讨论】:

    标签: swift ios15 sfsafariviewcontroller


    【解决方案1】:

    prefersEphemeralWebBrowserSession = true 它使您的浏览器进入私人模式!!! 所以你不需要注销。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-18
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 2017-04-27
      相关资源
      最近更新 更多