<small id='fFXv4'></small><noframes id='fFXv4'>

      <legend id='fFXv4'><style id='fFXv4'><dir id='fFXv4'><q id='fFXv4'></q></dir></style></legend>

    1. <tfoot id='fFXv4'></tfoot>
    2. <i id='fFXv4'><tr id='fFXv4'><dt id='fFXv4'><q id='fFXv4'><span id='fFXv4'><b id='fFXv4'><form id='fFXv4'><ins id='fFXv4'></ins><ul id='fFXv4'></ul><sub id='fFXv4'></sub></form><legend id='fFXv4'></legend><bdo id='fFXv4'><pre id='fFXv4'><center id='fFXv4'></center></pre></bdo></b><th id='fFXv4'></th></span></q></dt></tr></i><div id='fFXv4'><tfoot id='fFXv4'></tfoot><dl id='fFXv4'><fieldset id='fFXv4'></fieldset></dl></div>
      • <bdo id='fFXv4'></bdo><ul id='fFXv4'></ul>
    3. 使用保存在 iOS 应用程序的沙箱(文档目录)中的 .html、.js 文件,这样我也可以在离线模式下打开 html 文

      时间:2023-10-21
      <legend id='a39RU'><style id='a39RU'><dir id='a39RU'><q id='a39RU'></q></dir></style></legend>

        <small id='a39RU'></small><noframes id='a39RU'>

          <tfoot id='a39RU'></tfoot>
          • <bdo id='a39RU'></bdo><ul id='a39RU'></ul>
              <tbody id='a39RU'></tbody>

              • <i id='a39RU'><tr id='a39RU'><dt id='a39RU'><q id='a39RU'><span id='a39RU'><b id='a39RU'><form id='a39RU'><ins id='a39RU'></ins><ul id='a39RU'></ul><sub id='a39RU'></sub></form><legend id='a39RU'></legend><bdo id='a39RU'><pre id='a39RU'><center id='a39RU'></center></pre></bdo></b><th id='a39RU'></th></span></q></dt></tr></i><div id='a39RU'><tfoot id='a39RU'></tfoot><dl id='a39RU'><fieldset id='a39RU'></fieldset></dl></div>
                本文介绍了使用保存在 iOS 应用程序的沙箱(文档目录)中的 .html、.js 文件,这样我也可以在离线模式下打开 html 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我必须显示一个需要 highcharts.js、jquery.min.js 的 .html 文件才能显示图表.我打算在 UIWebView 中显示 .html 文件.

                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.

                我看到当文件(即 html、highcharts.js、jquery.min)在 Application Bundle 中时,我可以像这样使用它们--

                I saw that when the files(i.e. html, highcharts.js, jquery.min) are in the Application Bundle, I can use them like this--

                aPath = [[NSBundle mainBundle] pathForResource:@"htmlfile" ofType:@"html"];[self.graphWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:aPath isDirectory:NO]]];

                这里,htmlFile"的来源是这样的 -

                Here, the "htmlFile" has the source like this -

                 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>TITLE</title>
                
                <script type="text/javascript" src="jquery.min.js"></script>
                <script type="text/javascript" src="highcharts.js"></script>
                <script type="text/javascript" src="htmlfile.js"></script>
                <script type="text/javascript" src="global.js"></script>
                </head>
                <body>
                <div id="wrapper">
                
                <div id="container"></div>    
                </div>
                </body>
                </html>
                

                所以,为了在 UIWebView 中显示内容,我只需在 Xcode 的 Build Phases 选项卡中将 .html 文件和 .js 文件制作为 Bundle Resources.

                So, in order to display the content in UIWebView, i just needed to make the .html file and .js files as Bundle Resources in Xcode's Build Phases Tab.

                问题:

                如上图所示源的.html文件保存在App的沙盒中时如何显示?

                How do display the .html file having the source like shown above when It is saved in the App's Sand Box?

                我试过了:

                1.我像这样在App SandBox中创建了一个文件夹--

                1. I created a folder in the App SandBox like this--

                NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是的);

                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;

                NSString aFolderPath = [(NSString)[paths objectAtIndex:0] stringByAppendingFormat:@"/%@",@"folder"];

                NSString aFolderPath = [(NSString)[paths objectAtIndex:0] stringByAppendingFormat:@"/%@",@"folder"];

                if(![[NSFileManager defaultManager] isWritableFileAtPath:aFolderPath]){
                

                [[NSFileManager defaultManager]createDirectoryAtPath:aFolderPath withIntermediateDirectories:NO attributes:nil error:nil];}

                [[NSFileManager defaultManager]createDirectoryAtPath:aFolderPath withIntermediateDirectories:NO attributes:nil error:nil]; }

                2.然后我像这样从App Bundle中复制了App SandBox中的html,js文件--

                2. Then I copied the html, js files in the App SandBox from the App Bundle like this--

                NSString *aJs = [[NSBundle mainBundle] pathForResource:@"JSFile"ofType:@"js"];

                NSString *aJs = [[NSBundle mainBundle] pathForResource:@"JSFile" ofType:@"js"];

                aJs = [NSString stringWithContentsOfFile:aGlobaljs encoding:NSUTF8StringEncoding error:nil];
                
                NSString *aPath = [(NSString*)[paths objectAtIndex:0] stringByAppendingFormat:@"/folder/%@",@"JSFile.js"];
                
                [aJs writeToFile:aPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
                

                现在所有需要的文件都在名为文件夹"的沙盒文件夹中,所以,我尝试像这样在 UIWebView 中打开保存的 html 文件--

                Now all the needed files are in the SandBox Folder named "folder", so, I tried to open the saved html file in the UIWebView like this--

                [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURLURLWithString:pathToHtmlFileinDocumentsDic relativeToURL:[NSURLURLWithString:aFolderPath]]]];

                [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:pathToHtmlFileinDocumentsDic relativeToURL:[NSURL URLWithString:aFolderPath]]]];

                这不起作用.

                推荐答案

                您必须将文件保存在您的应用程序资源中,这里的技巧是保持 JavaScript 文件与 HTML 文件的相对链接.添加 html 包时,选择为任何添加的文件夹创建文件夹引用".并在代码中像这样调用您的 html 页面:

                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];
                

                您的所有 Html 页面(包括 cssimagesjs)都位于 Help(或您拥有的任何其他名称)文件夹中.即,它就像在文件夹中维护一个本地静态站点

                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

                这篇关于使用保存在 iOS 应用程序的沙箱(文档目录)中的 .html、.js 文件,这样我也可以在离线模式下打开 html 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 iOS8 Swift XCode 6 通过 uiwebview 将新样式表注入网站 下一篇:即使我没有使用任何 UIWebView,Apple 也不会接受我的应用程序

                相关文章

              • <legend id='D0DIV'><style id='D0DIV'><dir id='D0DIV'><q id='D0DIV'></q></dir></style></legend>
                    <tfoot id='D0DIV'></tfoot>

                  1. <small id='D0DIV'></small><noframes id='D0DIV'>

                      <bdo id='D0DIV'></bdo><ul id='D0DIV'></ul>
                    <i id='D0DIV'><tr id='D0DIV'><dt id='D0DIV'><q id='D0DIV'><span id='D0DIV'><b id='D0DIV'><form id='D0DIV'><ins id='D0DIV'></ins><ul id='D0DIV'></ul><sub id='D0DIV'></sub></form><legend id='D0DIV'></legend><bdo id='D0DIV'><pre id='D0DIV'><center id='D0DIV'></center></pre></bdo></b><th id='D0DIV'></th></span></q></dt></tr></i><div id='D0DIV'><tfoot id='D0DIV'></tfoot><dl id='D0DIV'><fieldset id='D0DIV'></fieldset></dl></div>