简体   繁体   English

使用 Swift iOS 在 SFSafariViewController 中配置浏览器缓存

[英]Configure browser cache in SFSafariViewController using Swift iOS

In my application I am implementing a feature where for some part I need to open my website using SFSafariViewController.在我的应用程序中,我正在实现一个功能,在该功能中,我需要使用 SFSafariViewController 打开我的网站。 For this I don't want the user to login again in the web application as well, so before I open the SFSafariViewController I want to pass some token, mail and other required information.为此,我也不希望用户再次登录 Web 应用程序,因此在打开 SFSafariViewController 之前,我想传递一些令牌、邮件和其他所需信息。 So is this feasible and would allow me to use browser cache.这是否可行,并允许我使用浏览器缓存。

SFSafariViewController is very limited in what you can configure, as seen by the documentation: https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller . SFSafariViewController在您可以配置的内容方面非常有限,如文档所示: https : //developer.apple.com/documentation/safariservices/sfsafariviewcontroller Apple intentionally keeps cookies and safari configuration separate from apps that are using it for security and privacy reasons.出于安全和隐私原因,Apple 有意将 cookie 和 safari 配置与使用它的应用程序分开。

I don't know if this is exactly what you're seeing, but I faced a similar issue where, if a user logged in via SFSafariViewControler , then logged out (not using SFSafariViewController ), then logged in again, it wouldn't ask for a login/pass because it was still cached in the browser.我不知道这是否正是您所看到的,但我遇到了类似的问题,如果用户通过SFSafariViewControler登录,然后注销(不使用SFSafariViewController ),然后再次登录,它不会询问用于登录/通行证,因为它仍然缓存在浏览器中。

Pretty much the only 2 options for this are:几乎只有两个选项是:

  1. Have the logout flow take place within SFSafariViewController so that you can clear the cookies that way.让注销流程在SFSafariViewController以便您可以通过这种方式清除 cookie。
  2. Apple has a new auth flow class ASWebAuthenticationSession (docs here ) which has a new property you can set called prefersEphemeralWebBrowserSession which essentially opens the browser in private mode. Apple 有一个新的身份验证流类ASWebAuthenticationSession此处为文档),它有一个您可以设置的新属性,称为prefersEphemeralWebBrowserSession ,它本质上以私有模式打开浏览器。 This keeps any cookies from being stored in the browser.这可以防止任何 cookie 存储在浏览器中。 The only downside to this, is the prefersEphemeralWebBrowserSession property is only available in iOS 13+.唯一的缺点是, prefersEphemeralWebBrowserSession属性仅在 iOS 13+ 中可用。

If this is the same issue you're facing and you can limit your app to iOS 13+, then I would suggest the ASWebAuthenticationSession route, otherwise you may need to find another solution.如果这与您面临的问题相同,并且您可以将您的应用程序限制为 iOS 13+,那么我建议使用ASWebAuthenticationSession路由,否则您可能需要找到其他解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM