Open links in Safari instead of UIWebVIew?

后端 未结 7 1111
后悔当初
后悔当初 2020-12-02 20:52

I have an app with a UIWebView inside a UIViewController. I load HTML from a web service as a string like this:

self.webView loadH         


        
7条回答
  •  萌比男神i
    2020-12-02 21:06

    Add this in class..

    @interface yourViewController : UIViewController
    
    

    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..!! :)

提交回复
热议问题