how to open the url in safari not in webview

后端 未结 10 1794
时光说笑
时光说笑 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: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.

提交回复
热议问题