Skip to content Skip to sidebar Skip to footer

Using .html, .js File Saved In The Sandbox(documents Directory) Of An Ios App So That I Am Able To Open The Html File In Offline Mode As Well

I have to display an .html file which needs highcharts.js, jquery.min.js in order to display a graph. I am planning to display the .html file in a UIWebView. I saw that when the fi

Solution 1:

You will have to keep your files in your apps resources, the trick here is to maintain the relative linking of the JavaScript files with the HTML files. When adding your html package select "Create folder reference for any added folders". and call your html page like this in code:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"Help"];

  NSURL *indexUrl = [NSURL fileURLWithPath:filePath];

Where all your Html pages (including css, images, js) are in Help (or any other name you have) folder. i.e., its like maintaining a local static site inside the folder

Solution 2:

You can boot http server locally (via for example https://github.com/robbiehanson/CocoaHTTPServer) and set /<appPath>/Documents/yourFolder as server root. Then you can open in UIWebViewNSURL like this: http://localhost:8080/index.html

Post a Comment for "Using .html, .js File Saved In The Sandbox(documents Directory) Of An Ios App So That I Am Able To Open The Html File In Offline Mode As Well"