UIWebView没有让下一个Url加载

时间:2016-04-22 08:32:23

标签: ios

我正在使用原生兼网络iOS应用。当我尝试在任何按钮上按下UIWeb中加载Urls按下WebView内部时,我无法获取下一个要加载的URL。任何人都可以为此提出建议吗?提前致谢。

这是我的代码:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *myString = [[request URL] absoluteString];
    [myString lowercaseString];
    NSLog(@"%@",myString)
    NSDictionary *headers = [request allHTTPHeaderFields];
    BOOL hasReferer = [headers objectForKey:@"X"]!=nil;
    if (hasReferer)
    {
        return YES;
    }
    else
    {
        // relaunch with a modified request
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                NSURL *url = [request URL];
                NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
                [request setValue:X forHTTPHeaderField:@"X"];
                [request setValue:Y forHTTPHeaderField:@"Y"];                   
                [loadingWebView loadRequest:request];
            });
        });

        return NO;
    }
return 0;
}

1 个答案:

答案 0 :(得分:0)

设置委托

- (void)webViewDidStartLoad:(UIWebView *)webView;
- (void)webViewDidFinishLoad:(UIWebView *)webView;
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error;

在此方法中查看它返回的内容

并确保您传递的是正确的网址,即stringByAddingPercentEscapesUsingEncoding