Search code examples
objective-cxcodeuiwebview

open external links in safari.app from UIWebView xcode


i have created UIwebView and name it :webveiw in ViewController.h i add the following code to open external link in safari :

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

when run it does not working where i did wrong ??


Solution

  • Try set a delegate:

    -(void)viewDidLoad
    {
        myWebView.delegate = self;
    }
    

    And add protocol UIWebViewDelegate:

    @interface yourViewController : UIViewController <UIWebViewDelegate>