我想使用safari Cookie为我的应用验证用户身份。我能用SFSafariViewController做到这一点。但问题是我在我的应用程序中有UIWebView来显示一些信息。即使用户使用safari登录,也会要求他们通过UIWebView再次登录。我想同步这个。意味着如果用户通过safari登录他不应该再在app中登录。我知道safari和uiwebview不共享cookie,所以我想把所有东西都移到safari。是否可以在视图控制器内显示safari?
谢谢, Richa
答案 0 :(得分:0)
let vc = SFSafariViewController(url: URL, entersReaderIfAvailable:false)
vc.modalPresentationStyle = .popover
vc.preferredContentSize = CGSize(width: self.view.frame.width/2, height: self.view.frame.height/2) // Or put any size
if let popover = vc.popoverPresentationController {
popover.sourceView = self.view // You can also put the source button
popover.permittedArrowDirections = .any
popover.sourceRect = CGRect(x: 0, y: 0, width: 85, height: 30)
popover.delegate = self
self.present(vc, animated: true, completion: nil)
}
然后声明这个子类:
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate
但这只适用于iPad,所以就这样说:
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}