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.
Asked
Active
Viewed 5,706 times
3
-
What do you get back in *didFailLoadWithError*? – RedBlueThing Feb 24 '10 at 02:57
-
It would help if you described how you're trying to load data into the web view-- there's more than one way, so where's the content coming from? – Tom Harrington Feb 24 '10 at 03:55
-
1I should probably give you the benefit of the doubt, but are you sure your device is connected to the internet? Will Safari load pages correctly? – Garrett H Feb 24 '10 at 04:19
-
1Yes, there are two UIWebview controllers on Tabs; an About Page and a PHP Page. the About Page loads fine on Simulator & Device. The PHP page only loads on Simulator. the PHP Page shows a blank white screen on Device. [code] [phpPage loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.website.com/mypage.php"]]]; [/code] Thanks so much guys. – robMontesinos Feb 24 '10 at 04:39
-
[phpPage loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"website.com/mypage.php"]]]; Oops. Newbie. – robMontesinos Feb 24 '10 at 04:52
2 Answers
2
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.

Cody Gray - on strike
- 239,200
- 50
- 490
- 574

Srikanth
- 1,725
- 2
- 10
- 11
1
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.

RedBlueThing
- 42,006
- 17
- 96
- 122
-
THanks for the help guys. I get the following from didFailLoadWithError: An error happened during load: Error Domain=NSURLErrorDomain Code=-1004 UserInfo=0x1743c0 "can’t connect to host" – robMontesinos Feb 24 '10 at 06:25
-
What's interesting is that the other UIWebView connects with the same website yet a different page. And as before, both websites show up fine in the Simulator. GRRRR... – robMontesinos Feb 24 '10 at 06:27
-
-
Man, this is strange. I tried Safari on device and it says "no dice - cannot connect." And then the alert disappears. I have been able to hit the offending page with Safari and Firefox on my Mac, as well as through the Simulator. Just not the Device. I set up the webviewdelegate like you guys suggested and got the above 1004 error. Gremlins I telll ya... – robMontesinos Feb 24 '10 at 06:50
-
I changed the URL on the webview viewDidLoad to google and it shows up fine on the Device. Now my php file does a header(Location:url) call. Could this be messing things up? Does uiwebview not support php redirect? – robMontesinos Feb 24 '10 at 06:56
-
OMG. I am not worthy of this board. The redirect php line was sending the Device to localhost which of course the SImulator could see. Duh. "Thanks for your help guys," he says with head bowed in shame.. – robMontesinos Feb 24 '10 at 07:04
-
-
Thanks Cannonade. I couldn't of done it without the clues you guys gave me. I was unaware of uiwebviewdelegate and didFailLoadWithError which started on the trail of this little bugger. Thanks so much. Salud! – robMontesinos Feb 24 '10 at 07:23
-
@robmonesinos No problems. Re: "not worthy", the reason SO exists is to help with problems exactly like this one, you have nothing to be ashamed of :) – RedBlueThing Feb 24 '10 at 22:03