2016-09-23 32 views
0

ViewController內使用SafariViewController我想使用Safari瀏覽器來驗證我的應用程序的用戶。我可以用SFSafariViewController來完成。但問題是我的UIWebView在我的應用程序中顯示一些信息。即使用戶使用Safari瀏覽器登錄,他們也會被要求通過UIWebView再次登錄。我想同步這個。意思是如果用戶通過safari登錄,他不應該再次登錄app.I知道safari和uiwebview不共享cookie,所以我想將所有內容都移到safari。是否有可能在視圖控制器內顯示safari?在像UIWebview

感謝, Richa

回答

0

PopoverViewController方法

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 
} 

Result