iPhone UIWebview Loads on Simulator But not on Device
I have a UIWebview on a Tab Bar that loads properly on the Simulator but not on the Device. Has anyone ever come 开发者_运维问答across this situation? I've been looking all over the Google- machine for the last three days to no avail. Any help would be hugely appreciated.
I faced the same problem. The solution evaded me a lot of time, but what I discovered was that I had:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"shouldStartLoadWithRequest Loading: %@", [request URL]);
}
and I did not return any thing from this. When I changed it to
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"shouldStartLoadWithRequest Loading: %@", [request URL]);
return TRUE;
}
it works. Simulator does not care if you returned a BOOL or not, but the actual device, it does not work.
First check your connectivity. Are you able to access both URLs (about and PHP page) from Safari on the device?
Then I suggest you stick some error handling code in your UIWebViewDelegate. So something like :
- (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];
}
Let us know how you go.
精彩评论