0

I want to use safari cookies to authenticate users for my app. I am able to do it with SFSafariViewController. But the problem is i have UIWebView in my app to show some information. Even though user is logged in using safari, they are asked to login again through UIWebView. I want to sync this. Means if user is logged in by safari he should not have to login again in app.I know that safari and uiwebview don't share cookies and so i want to move everything to safari. Would it be possible to show safari inside of a view controller?

Thanks, Richa

Richa Srivastava
  • 482
  • 1
  • 7
  • 24

1 Answers1

0

PopoverViewController method

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

Then declare this subclass:

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate

But this is only work for iPad, so put this:

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
}

Result

Community
  • 1
  • 1