【问题标题】:iOS show webview offline with imagesiOS 离线显示带有图像的 webview
【发布时间】:2016-03-12 19:09:18
【问题描述】:

我正在尝试下载网页 (html),然后在 UIWebView 中显示已下载的本地 html。它正在工作,但离线 UIWebView 没有显示图像。 这是我的代码:

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];


    NSURL *url = [NSURL URLWithString:@"https://www.mypage.com"];
    NSData *urlData = [NSData dataWithContentsOfURL:url];
    [urlData writeToFile:filePath atomically:YES];



[Website loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];




}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

}

@end

谁能分享一些示例代码来添加网站内容(图片)? 任何帮助,将不胜感激。谢谢!

【问题讨论】:

    标签: ios uiwebview


    【解决方案1】:

    HTML 很可能引用了您未同时下载的图像。第一步是解析 HTML 并下载图像。然后,如果图像引用与基本文档无关,您可能需要修复 HTML 的本地副本。例如,如果它们引用不同服务器上的图像,您必须在内部修复这些链接。如果原始文档使用 Javascript 动态加载图像,它可能永远不会按您想要的方式工作。

    【讨论】:

      猜你喜欢
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 1970-01-01
      相关资源
      最近更新 更多