Open links in Safari instead of UIWebVIew? Open links in Safari instead of UIWebVIew? ios ios

Open links in Safari instead of UIWebVIew?


Have you set the delegate of the UIWebView to your UIViewController? There's nothing obviously wrong with your code as far as I can see, so it's likely to be something small like that.


Add this in class..

@interface yourViewController : UIViewController<UIWebViewDelegate>

Add this in View did load

- (void)viewDidLoad{    [description loadHTMLString:string baseURL:nil];        description.delegate = self;}

Add this in your .m file

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {    if ( inType == UIWebViewNavigationTypeLinkClicked ) {        [[UIApplication sharedApplication] openURL:[inRequest URL]];        return NO;    }    return YES;}

Note:

UIWebView *description;@synthesize description;

Then It will work perfectly the way you deserve..!! :)


Set the delegate of the UIWebView to your UIViewController after that use this UIWebview method and check the condition, for example now webview current url is google.com, if suppose you clicked on gmail the url contains the string with gmail. Use the below method it opened a safari browser and automatically loaded that url.

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {    if ( inType == UIWebViewNavigationTypeLinkClicked ) {        NSURL *url = [inRequest URL];        if ([[url absoluteString] rangeOfString:@"gmail"].location == NSNotFound) {            [[UIApplication sharedApplication] openURL:[inRequest URL]];            return NO;        }    }    return YES;}


matomo