Swift Open Link in Safari

前端 未结 10 2433
北荒
北荒 2020-12-01 00:41

I am currently opening the link in my app in a WebView, but I\'m looking for an option to open the link in Safari instead.

10条回答
  •  天涯浪人
    2020-12-01 00:54

    New with iOS 9 and higher you can present the user with a SFSafariViewController (see documentation here). Basically you get all the benefits of sending the user to Safari without making them leave your app. To use the new SFSafariViewController just:

    import SafariServices
    

    and somewhere in an event handler present the user with the safari view controller like this:

    let svc = SFSafariViewController(url: url)
    present(svc, animated: true, completion: nil)
    

    The safari view will look something like this:

提交回复
热议问题