I would like to open all external links which are in my application
(UIWebView
) not inside the app, but in Safari. How can I do that?
I have implement UiWebViewDelegate.
Working solution for my question bellow:
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if navigationType == UIWebViewNavigationType.LinkClicked{
UIApplication.sharedApplication().openURL(request.URL!)
return false
}
return true
}
@Leo Dabus thanks a lot for this hint, but I guess I have a better solution:
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if navigationType == UIWebViewNavigationType.LinkClicked{
UIApplication.sharedApplication().openURL(request.URL!)
return false
}
return true
}
this one works perfect.
Solution for objective-c :-
in ViewController.h
@interface ViewController : UIViewController<UIWebViewDelegate>
in ViewController.m
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (navigationType == UIWebViewNavigationTypeLinkClicked){
NSURL *url = request.URL;
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
return NO;
}
return YES;
}