Make links inside a UIWebView clickable
suggest changeIn vc.h
@interface vc : UIViewController<UIWebViewDelegate>
in vc.m
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (navigationType == UIWebViewNavigationTypeLinkClicked){
// Open the link in the browser. To load it in this web view, remove the return NO.
NSURL *url = request.URL;
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
return NO;
}
return YES;
}
Set the web view’s delegate to this controller, or the method is never called. openURL: is the pre-iOS 10 call. iOS 10 and later use openURL:options:completionHandler:.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents