views:

409

answers:

1

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.

+1  A: 

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.

Cannonade
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"
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 How did you go in Safari on the same URLs?
Cannonade
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...
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?
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..
Awesome! Glad you got it sorted.
Cannonade
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!
@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 :)
Cannonade