Force iOS应用程序在Safari中打开外部链接 [英] Force iOS app opens external links in safari

查看:146
本文介绍了Force iOS应用程序在Safari中打开外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序,我使用PhoneGap和JQuery移动。该应用程序有一些外部链接,我想在移动safari打开,但现在,他们只是在应用程序视图中打开。链接如下所示:

I have an iOS app that I made using PhoneGap and JQuery mobile. The app has some external links that I want to open in mobile safari but as of now, they just open in the app view. The links are written like this :

<a rel="external" href="wwww.example.com">Click Here</a>



我阅读JQuery手机文档,并表示添加 rel =external 会解决这个问题,但显然不是。有任何想法吗?请记住,这是一个基于HTML的应用程序。

I read JQuery mobiles docs and it stated that adding rel="external" would solve this but apparently not. Any ideas? Keep in mind, this is a HTML base app.

推荐答案

最后能够通过导航到MainviewController.m,对于其中提到webView的部分,其他帖子中提到,然后更改从这

Finally was able to do it by navigating to MainviewController.m and looking for a section where it mentioned webView as mentioned in the other posts then changing it from this

/* Comment out the block below to over-ride */

/*

- (void) webViewDidStartLoad:(UIWebView*)theWebView
{
    return [super webViewDidStartLoad:theWebView];
}

- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
    return [super webView:theWebView didFailLoadWithError:error];
}

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
*/

TO

/**

 * Start Loading Request

 * This is where most of the magic happens... We take the request(s) and process the response.

 * From here we can re direct links and other protocalls to different internal methods.

 */

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

{

    NSURL *url = [request URL];

    // add any other schemes you want to support, or perform additional

    // tests on the url before deciding what to do -jm

    if( [[url scheme] isEqualToString:@"http"] ||

       [[url scheme] isEqualToString:@"https"])

    {

        [[UIApplication sharedApplication] openURL:url];

        return NO;

    }

    else

    {

        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];

    }



}

我没有使用objective-c的经验,所以我不得不尝试这个,所以我很高兴我得到它的工作。

Im have no experience with objective-c so I had to experiment with this so I'm glad I got it to work.

这篇关于Force iOS应用程序在Safari中打开外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆