UIWebView链接在Safari中打开

Gyp*_*psa 6 iphone objective-c uiwebview

我想在我的webView中打开iTunes链接,但是当webView启动页面时,它会重定向到Safari浏览器.在那里,网址正在打开,但我希望它在我的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];
}
Run Code Online (Sandbox Code Playgroud)

请建议一种解决此问题的方法.

Pen*_*One 1

您可能想尝试在运行应用程序时记录加载请求。苹果可能会自动更改http://itms-appshttp://phobos或类似的内容。如果是这样,那么您可以在调用时阻止负载,如下所示:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

祝你好运。我很想知道最终的效果是什么。