0

I am having some set of html files and want to switch between them in a webView.

When i try to load any html then it gives me some thing like this

Load error,The opertaion couldn't be completed.(NSURLErrorDomain error -999.)

How would i fix this issue.

for loading htm i am using the lines of code

self.playerPath = [[BundleUtils bundleDirectoryFor:nil] stringByAppendingPathComponent:@"Browser Player files/HTMLplayer/RENE001NL_p001_G02_20_meeleesboek_XCode_pagetr_test_Newgen/"];
        NSString* indexFilePath = [self.playerPath stringByAppendingPathComponent:@"index001.html"];
        NSURL* indexUrl = [NSURL fileURLWithPath:indexFilePath];
        [self.browserView loadRequest:[NSURLRequest requestWithURL:indexUrl]];




    + (NSString *) bundleDirectoryFor:(NSString *) bundleName
    {
        NSString* bundlePath = nil;

        if (bundleName) {
            NSString* basePath = [[[NSBundle mainBundle] resourcePath]
                              stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.bundle", bundleName]];
            NSBundle* bundle = [NSBundle bundleWithPath:basePath];
            bundlePath = [bundle resourcePath];
        } else {
            bundlePath = [[NSBundle mainBundle] resourcePath];
        }

        return bundlePath;
    }
5
  • could you show your code? how are you loading the html? Commented Jul 7, 2011 at 7:05
  • Ok give my code for loading html. Commented Jul 7, 2011 at 7:09
  • Can you post your code how you are setting request ? Commented Jul 7, 2011 at 7:10
  • I have given code which i am using for load request and code for making url for request. Commented Jul 7, 2011 at 7:13
  • Can you read the html using [NSData dataWithContentsOfFile:]? If not, I'd say there's a problem with the file itself - either it's not actually at that location in your bundle (likely) or you don't have permission to access it (less likely). Commented Jul 7, 2011 at 7:18

2 Answers 2

1

EDIT:

would you try and escape your path before creating the NSURL?

 ....
 NSString* encodedParam =  [indexFilePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 NSURL* indexUrl = [NSURL fileURLWithPath:encodedParam];
 ....

EDIT 2:

You can inspect the content of your app binary by revealing it in the finder (right click on the product tab in Xcode) and then selecting "show package content". You will see exactly where your html is located and will be able to adjust the value you pass in.

OLD ANSWER:

I see two issues with your code:

  1. you are using loadRequest, which is fine to retrieve content from the network, but (I guess) not fine to load a local file;

  2. use of a full path (Browser Player files/HTMLplayer/RENE001NL_p001_G02_20_meeleesboek_XCode_pagetr_test_Newgen/) while an iphone app binary structure is a flat directory (i.e., all the different folders you might have in Xcode are flattened out to a single directory).

I would suggest trying with this code:

NSString* basePath = [[NSBundle mainBundle] bundlePath];
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"index001" ofType:@"html"];  
NSData* myData = [NSData dataWithContentsOfFile:filePath];
if (myData) {
    [_webView loadData:myData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:[NSURL fileURLWithPath:basePath]];
          ....
Sign up to request clarification or add additional context in comments.

4 Comments

But same code for different html file in different folder is working
That error not come now but it gives, url not found on Host.i am having folder in my resources at same location and also html file.
Have you read my EDIT 2? Where is the html file actually located in your app bundle?
+1 Thanx for your support and answers.I use other html, that works fine. I think problem in content,or java script file which are used in that file. Send it to client for new file.
0

The error seems like you have cancelled a ongoing load request.

NSURLErrorCancelled
Returned when an asynchronous load is canceled.
A Web Kit framework delegate will receive this error when it performs a cancel operation
on a loading resource. Note that an NSURLConnection or NSURLDownload delegate 
will not receive this error if the download is canceled.
Available in Mac OS X v10.2 and later.
Declared in NSURLError.h.

Probably the way either your html is referencing to another link or webview delegate is cancelling the load operation. Hard to guess why this has occured.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.