Open links in Safari instead of UIWebVIew?

后端 未结 7 1136
后悔当初
后悔当初 2020-12-02 20:52

I have an app with a UIWebView inside a UIViewController. I load HTML from a web service as a string like this:

self.webView loadH         


        
7条回答
  •  孤街浪徒
    2020-12-02 21:15

    Apple introduced a Safari View Controller on iOS 9. Safari View Controller brings all of the features user expect from Safari over to your app without ever leaving it.

    First we need to import Safari Services

    #import 
    

    For Objective C:-

    NSString *yourUrl = @"http://yourURL";
    SFSafariViewController *svc= [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString: yourUrl]];
    [self presentViewController:svc animated:YES completion:nil];
    

    For Swift:-

    let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)
    self.presentViewController(svc, animated: true, completion: nil)
    

提交回复
热议问题