0

I am having difficulties gettin a webpage to load in my app. I think the issue has to do with it having back to back / in it at one point, but am not sure how to work around this. The URL I want it to visit is http://kaiopublications.org/content//iLuminateVol1.1/index.html

Here is my code:

- (void)viewWillAppear:(BOOL)animated {
    NSString *html = _entry.articleUrl;

        NSURL *url = [NSURL URLWithString:html];
    NSLog(@"URL%@", html);
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];

}

The log for html comes back with the correct address, but if I run a log on url, it comes back null.

user717452
  • 33
  • 14
  • 73
  • 149

2 Answers2

1

It must be something else or you may just need to wait. I tried it quickly myself and I can load the site with this URL in my test app. But I realize the site did load very slowly even on the simulator with a regular internet connection. If you try it on your device with a poor mobile bandwidth it maybe just takes very long.

One more thought. Is there any "noise" character at the end of the string?

Try this to see if it is that:

NSURL *url = [NSURL URLWithString:@"http://kaiopublications.org/content//iLuminateVol1.1/index.html"];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
hol
  • 8,255
  • 5
  • 33
  • 59
  • That was the issue...had some spaces at the beginning of the string that was making issues. I'll accept this as the answer when it lets me. – user717452 May 13 '13 at 19:40
  • Very good you can trim the string. I found this http://stackoverflow.com/questions/4645649/remove-whitespace-from-string-in-objective-c as a solution. – hol May 13 '13 at 19:43
0

Add some delegate methods to help you diagnose this. So you can display an activityIndicatorView while waiting for loads. It could be a slow site or it could be the delegate not setup.

#pragma mark - UIWebView delegate methods

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    if (!_activity.isAnimating)
        [_activity startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_activity stopAnimating];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (!_activity.isAnimating)
        [_activity startAnimating];
    return YES;
}
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42