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

前端 未结 2 966
走了就别回头了
走了就别回头了 2020-12-21 13:46

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 t

相关标签:
2条回答
  • 2020-12-21 14:06

    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

    0 讨论(0)
  • 2020-12-21 14:12

    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 UIWebView NSURL like this: http://localhost:8080/index.html

    0 讨论(0)
提交回复
热议问题