how to open the url in safari not in webview

后端 未结 10 1718
时光说笑
时光说笑 2020-12-28 16:18

I want to open an url in safari, outisde the app and not in webview.

I implemented the UIWebViewDelegate but I am still not able to open the url. Basically I am not

相关标签:
10条回答
  • 2020-12-28 16:36

    I found this answer in google but I need to after opening the browser terminate my application and continue the browser.

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"] options: @{} completionHandler: nil];
    

    in Android can do It easy to calling finish() method how can I do that

    0 讨论(0)
  • 2020-12-28 16:37

    This answer was readily available via Google:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apple.com"]];
    

    Just put that in your button press or whatever event you're wanting to call it on, and then pass it a URL (replace the @"http:/www.apple.com").

    0 讨论(0)
  • 2020-12-28 16:38
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
        if (![[NSString stringWithFormat:@"%@",[request URL]] containsString:@"file"] ) {
            [[UIApplication sharedApplication] openURL:[request URL]];
            return NO;
        }
        return YES;
    }
    

    I used an html file in local. In this html there is some links. If you set delegate UIWebViewDelegate and use this local html will open in your webView and the other links will open in safari
    I wrote "file" because this link is "file:///Users/~/x.app/about.html" in local.

    0 讨论(0)
  • 2020-12-28 16:40

    Swift 3 (iOS 10+):

    if let url = URL(string: "http://www.seligmanventures.com") {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    }
    
    0 讨论(0)
  • 2020-12-28 16:44

    For iOS 10+

    // Objective-C
    UIApplication *application = [UIApplication sharedApplication];
    [application openURL:URL options:@{} completionHandler:nil];
    
    // Swift
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
    

    For more info refer THIS.

    0 讨论(0)
  • 2020-12-28 16:44

    ******************** Swift **********************

    //MARK: Button Click on open with SafariViewController

    private var urlString:String = "https://google.com"
    
    @IBAction func openWithSafariVC(sender: AnyObject)
    {
    
        let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)
        svc.delegate = self
        self.presentViewController(svc, animated: true, completion: nil)
    }
    

    //MARK: SafatriViewConroller Dismiss

    func safariViewControllerDidFinish(controller: SFSafariViewController)
    {
    
        controller.dismissViewControllerAnimated(true, completion: nil)
    }
    
    0 讨论(0)
提交回复
热议问题