0

I'm using a UIWebView to load a static resource shipped within my application bundle. Sometimes, I have no clear what the problem could be, I receive the following error within the delegate method - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1001

The resource is loaded through a NSURLRequest where I set up a timeout interval of 10 seconds, but that interval is not followed. In fact, in the debug console I'm able to see that the error delegate is called after about 2 seconds.

NSURL *htmlFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"root" ofType:@"html"] isDirectory:NO];
NSURLRequest* htmlRequest = [NSURLRequest requestWithURL:htmlFile cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];

[webView loadRequest:htmlRequest];

The fact is that I cannot always replicate the problem I have. Any suggestions?

P.S. I'm working with an app that runs from 4.3. The problem is also with iOS 7.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190

2 Answers2

1

According to apple CFNetwork Error Codes Reference this code is a timeout error:

kCFURLErrorTimedOut  = -1001

Timeout are not always easy to reproduce most likely you should extend the timeout value when you init the NSURLRequest.

According to the same docs you can query the object for additional information.

For example:

if (CFEqual(CFErrorGetDomain(err), kCFErrorDomainCFNetwork) && CFErrorGetCode(err) == kCFHostErrorUnknown) {

    CFDictionaryRef userInfo = CFErrorCopyUserInfo(err);

    CFNumberRef number = (CFNumberRef) CFDictionaryGetValue(userInfo, kCFGetAddrInfoFailureKey);

    ...

    CFRelease(userInfo);
}
meda
  • 45,103
  • 14
  • 92
  • 122
0

I suppose that the resource you are looking for is not available. Be sure that the path is correct (ios is case sensitive) and if you are downloading some contents from internet be sure that the download is completed and the file is copied from the temporary folder to the final destination.

IgnazioC
  • 4,554
  • 4
  • 33
  • 46
  • Thanks for your reply. The resource is available since I'm able to see it in the web view. **Sometimes** (I cannot replicate it) it does not load correctly. Updated with some code. – Lorenzo B Aug 02 '14 at 14:55