0

I made an hybrid app between objective C and javascript. My app works so:

  1. When I press on the first button it will load a UIWebView
  2. In this UIWebView I can save the html to the Documents folder
  3. When I save the website I create a JSON to store informations and I save this JSON to Documents folder
  4. When I press the second button, it will load another UIWebView in which there are a mobile site that read informations from JSON and present this data in a html list
  5. When I press on the name of one site it will load the site from Documents folder

The first 4 points works great, but when I press on the site title I've trouble, indeed, the UIWebView shows me a page in which there are written that the page it's not stored on this server. When I navigate with Finder to the Documents folder of my app and I double click on the html site it shows me it in Safari. Why when I load it with an UIWebView doesn't work? I will post here a screenshot to understand my flow.

enter image description here

CODE: I post here the code to load the html:

viewDidLoad method where I call the method to load my page

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webView.delegate = self;
    //[self loadWebsite:@"http://localhost/root/main/index.html"];
    [self loadWebsite:@"http://192.168.2.1/root/main/index.html"];
}

loadWebsite method

-(void)loadWebsite:(NSString*)site
{
    NSURL *url = [NSURL URLWithString:site];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView setScalesPageToFit:YES];
    [self.webView loadRequest:request];
}
lucgian84
  • 833
  • 4
  • 11
  • 29

1 Answers1

0

This seems like a problem with how you are loading your html file into the webview. You should post the code where you are loading the uiwebview.

To load a webview with a local file use the following code :

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
pathForResource:@"htmlfilename" ofType:@"html" inDirectory:@"Documents"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];

You can refer to this post : Load resources from relative path using local html in uiwebview

Community
  • 1
  • 1
rbertsch8
  • 222
  • 2
  • 12
  • so can you clarify: in step 5 are you loading a local HTML file in the Documents folder or a HTML file from a server? Is your "Documents" folder a folder within your xcode project or are you referring to the documents folder of OSX – rbertsch8 Aug 01 '13 at 15:28
  • I'm trying to load a local HTML file stored in Documents folder.To build the html list I made so: I parse the JSON file (created when I press on the first button) and with `stringByEvaluatingJavaScriptFromString` I run a javascript method to make the html list. In the JSON file I've a row in which I stored the title of the site I stored and a row in which I stored the path to my Documents folder. So for example my list is made so: `` – lucgian84 Aug 01 '13 at 15:42