iOS UIWebView app opens link in Safari

后端 未结 2 1177
太阳男子
太阳男子 2021-01-18 15:24

I have an iOS app which has only one view and that is UIWebView (It opens the main content of the app). I would like when I make a click somewhere(e.g on a table row) the a

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 15:45

    In case the above answer does not work for you you can fix it in an iOS way. For that you need to implement the webView:shouldStartLoadWithRequest UIWebViewDelegate protocol method where to check your URL.

     - (BOOL) webView: (UIWebView *) theWebView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType
    {
        NSURL *url = [request URL];
        // check URL in your if condition
        if (...) {
            //open URL in Safari
            [[UIApplication sharedApplication] openURL:url];
            return NO;
        }
        else
            return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
    }
    

    There is a constraint with the above answer, you need to implement the mechanism of notifying the ios app from JQuery, possible workaround is discussed here: https://stackoverflow.com/a/11633460/3317354

提交回复
热议问题