I'm pretty new to Xcode... I have a single page iOS app that just has a UIWebView opening a specific URL. I would like any links within the pages that have target="_blank"
to open in Safari, rather than inside the app.
Can someone tell me how to accomplish this? (I've searched everywhere) and also tell me in which files and where to put the code? Thank you SOOO much!!
EDIT
I implemented the following code in my ViewController.m file:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Add line below so that external links & PDFs will open in Safari.app
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com/"]]];
}
// Add section below so that external links & PDFs will open in Safari.app
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:request.URL];
return false;
}
return true;
}
But for the line webView.delegate = self;
I am getting a yellow warning that says:
Assigning to 'id'from incompatible type 'UIWebViewViewController *const_strong'
What is this error, and how can I fix it in Xcode?