iPhone UIWebview在模拟器上加载但不在设备上加载

时间:2010-02-24 02:50:58

标签: iphone uiwebview

我在标签栏上有一个UIWebview,可以在模拟器上正确加载,但不能在设备上加载。有没有人遇到过这种情况?过去三天我一直在寻找整个谷歌机器无济于事。任何帮助都将非常感激。

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。解决方案让我避开了很多时间,但我发现的是我有:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"shouldStartLoadWithRequest Loading: %@", [request URL]);
}

我没有从中返回任何东西。当我把它改成

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"shouldStartLoadWithRequest Loading: %@", [request URL]);
        return TRUE;

}

它有效。模拟器不关心你是否返回BOOL,但是实际的设备,它不起作用。

答案 1 :(得分:1)

首先检查您的连接。您是否能够从设备上的Safari访问这两个URL(about和PHP页面)?

然后我建议您在 UIWebViewDelegate 中添加一些错误处理代码。如下所示:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    // load error, hide the activity indicator in the status bar
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    if ([error code] == NSURLErrorCancelled) {
        // don't show the error

        // if you want to know why I ignore these errors
        // check out this question:
        // http://stackoverflow.com/questions/1577670
        return;
    }   

    [webView loadHTMLString:[[[NSString alloc] initWithFormat:@"Failed to load page %@ %08d", [error localizedDescription, [error code]]] autorelease] baseURL:nil];
}

告诉我们您的情况。

相关问题