<tfoot id='x8erL'></tfoot><legend id='x8erL'><style id='x8erL'><dir id='x8erL'><q id='x8erL'></q></dir></style></legend>
      • <bdo id='x8erL'></bdo><ul id='x8erL'></ul>

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

        iOS 下载并保存 HTML 文件

        时间:2023-10-02
        • <legend id='qwYSs'><style id='qwYSs'><dir id='qwYSs'><q id='qwYSs'></q></dir></style></legend>

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

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

                <tfoot id='qwYSs'></tfoot>
                  本文介绍了iOS 下载并保存 HTML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试下载网页 (html),然后在 UIWebView 中显示已下载的本地 html.

                  I am trying to download a webpage (html) then display the local html that has been download in a UIWebView.

                  这是我尝试过的-

                  NSString *stringURL = @"url to file";
                  NSURL  *url = [NSURL URLWithString:stringURL];
                  NSData *urlData = [NSData dataWithContentsOfURL:url];
                  if ( urlData )
                  {
                      NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                      NSString  *documentsDirectory = [paths objectAtIndex:0];  
                  
                      NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"index.html"];
                      [urlData writeToFile:filePath atomically:YES];
                  }
                  
                      //Load the request in the UIWebView.
                      [web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];        // Do any additional setup after loading the view from its nib.
                  

                  但这会产生SIGABRT"错误.

                  But this gives a 'SIGABRT' error.

                  不太确定我做错了什么?

                  Not too sure what I have done wrong?

                  任何帮助将不胜感激.谢谢!

                  Any help would be appreciated. Thanks!

                  推荐答案

                  传递给 UIWebView 的路径不正确,就像 Freerunnering 提到的,试试这个吧:

                  The path passed to the UIWebView is incorrect, like Freerunnering mentioned, try this instead:

                  // Determile cache file path
                  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                  NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];   
                  
                  // Download and write to file
                  NSURL *url = [NSURL URLWithString:@"http://www.google.nl"];
                  NSData *urlData = [NSData dataWithContentsOfURL:url];
                  [urlData writeToFile:filePath atomically:YES];
                  
                  // Load file in UIWebView
                  [web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];      
                  

                  注意:需要添加正确的错误处理.

                  Note: Correct error-handling needs to be added.

                  这篇关于iOS 下载并保存 HTML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UITableViewCell中的文本居中对齐问题 下一篇:如何在触摸事件上画线?

                  相关文章

                  <tfoot id='l1Ft3'></tfoot>
                  1. <legend id='l1Ft3'><style id='l1Ft3'><dir id='l1Ft3'><q id='l1Ft3'></q></dir></style></legend>

                  2. <small id='l1Ft3'></small><noframes id='l1Ft3'>

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