0

I want to modify my code in order to open the external links on Safari instead of the in-app browser of my app. The html files are loaded from an internal path, so I don't know how to make the app understand that all the external links have to be opened in safari.

This is my ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *fullURL = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_viewWeb loadRequest:requestObj];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

How should I modify it? Thanks!

ElMastro
  • 3
  • 2
  • 3
    possible duplicate of [How to launch safari and open URL from iOS app](http://stackoverflow.com/questions/12416469/how-to-launch-safari-and-open-url-from-ios-app) – Shamas S Sep 07 '15 at 09:03

1 Answers1

1

You need to handle this in the UIWebView delegate method and check with the UIWebViewNavigationType.

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

        if(navigationType == UIWebViewNavigationTypeLinkClicked){

          [MAIN_APPLICATION_DELEGATE openURL:request.URL];
    }
}
Nipun Arora
  • 372
  • 1
  • 10