There is an application that opens a web page. On the page there are buttons whose links contain the same key. Dk, here's how, before opening the page, run the link through if for the presence of a specific fragment and make a decision, open it in the application or in safari?

1 answer 1

UIWebViewDelegate has a method - shouldStartLoadWith . Be sure not to forget - UIWebViewDelegate when declaring a class.

If Swift :

 class ViewController: UIViewController, UIWebViewDelegate { 

If Objective-C :

 @interface ViewController () <UIWebViewDelegate> 

Well, and then the code itself:

If Swift :

 func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool { let url = request.url?.absoluteString if (url?.range(of: "#") != nil) { //url содержит знак - # } return true } 

If Objective-C :

 -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSString *urlString = request.URL.absoluteString; if ([urlString rangeOfString:@"#"].location != NSNotFound) { //URL содержит знак # } return YES; }