doctorpi_

Untitled

May 8th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public func authorizeSafariEmbedded(from controller: UIViewController, at url: URL) throws -> SFSafariViewController {
  2. safariViewDelegate = OAuth2SFViewControllerDelegate(authorizer: self)
  3. let web = SFSafariViewController(url: url)
  4. web.title = oauth2.authConfig.ui.title
  5. web.delegate = safariViewDelegate as! OAuth2SFViewControllerDelegate
  6. //controller.addChild(web)
  7. controller.view.addSubview(web.view)
  8.  
  9. web.didMove(toParent: controller)
  10. web.view.translatesAutoresizingMaskIntoConstraints = false
  11. if #available(iOS 11.0, *) {
  12. web.view.topAnchor.constraint(equalTo: controller.view.safeAreaLayoutGuide.topAnchor, constant: 30).isActive = true
  13. web.view.bottomAnchor.constraint(equalTo: controller.view.safeAreaLayoutGuide.bottomAnchor, constant: -30).isActive = true
  14. web.view.leadingAnchor.constraint(equalTo: controller.view.safeAreaLayoutGuide.leadingAnchor, constant: 30).isActive = true
  15. web.view.trailingAnchor.constraint(equalTo: controller.view.safeAreaLayoutGuide.trailingAnchor, constant: -30).isActive = true
  16. } else {
  17. // Fallback on earlier versions
  18. }
  19.  
  20.  
  21.  
  22. web.modalPresentationStyle = oauth2.authConfig.ui.modalPresentationStyle
  23.  
  24. willPresent(viewController: web, in: nil)
  25.  
  26. controller.present(web, animated: false,completion: nil)
  27.  
  28. return web
  29. }
Advertisement
Add Comment
Please, Sign In to add comment