UIWebView链接在Safari中打开 [英] UIWebView links opening in Safari

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

问题描述

我想在我的webView中打开iTunes链接,但是当webView启动页面时,它会重定向到Safari浏览器。在那里,网址正在打开,但我希望它在我的webView中打开。

I want to open an iTunes link in my webView, but when the webView launches the page, it redirects to the Safari browser. There, the url is getting opened, but I want it to open in my webView.

- (void)viewDidLoad {

    NSString *urlAddress = @"http://itunes.apple.com/us/app/foodcheck-traffic-light-nutrition/id386368933?mt=8";

    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    //Load the request in the UIWebView.
    [webView loadRequest:requestObj];

    [super viewDidLoad];
}

请提供一种解决此问题的方法。

Please suggest a way to sort out this problem.

推荐答案

您可能希望在运行应用程序时尝试记录加载请求。可能是苹果自动将 http:// 更改为 itms-apps http :// phobos 或这些行中的某些内容。如果是这样,那么你可以使用以下内容阻止加载:

You may want to try logging the load requests when you run the app. It may be that apple is automatically changing http:// to itms-apps or http://phobos or something along these lines. If so, then you can block the load when it's call using something like this:

- (BOOL)webView:(UIWebView *)webView 
shouldStartLoadWithRequest:(NSURLRequest *)request 
 navigationType:(UIWebViewNavigationType)navigationType;
{   
    NSURL *loadURL = [[request URL] retain];
    NSLog(@"%@",loadURL);
    if([[loadURL absoluteString] hasPrefix:@"http://"])
    {
        [loadURL release]; 
        return TRUE;
    }
    [loadURL release];
    return FALSE;
}

祝你好运。我很想知道最终会有什么用。

Good luck. I'm curious to know what finally works.

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

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