ios打不开html文件,在DocumentsWeb目录中打开UIWebview时,ios-css和js在html文件中无法链接...

显然,以编程方式加载HTML文件时,文档库与应用程序的Documents目录不同.

查看HTML中的BASE元素,它位于< head>内.元件:

gt;

Meta charset="utf-8">

要解决此问题,您将手动提供文档基本URL.您还没有发布代码如何以编程方式加载index.html文件,因此我假设您正在使用以下UIWebView方法:

- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

所以现在试试这段代码,看看它是否解决了你的问题:

// Get the app Documents path

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

NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

// Add www/index.html to the basepath

NSString *fullFilepath = [basePath stringByAppendingPathComponent:@"www/index.html"];// This must be filled in with your code

// Load the file,assuming it exists

NSError *err;

NSString *html = [NSString stringWithContentsOfFile:fullFilepath encoding:NSUTF8StringEncoding error:&err];

// Load the html string into the web view with the base url

[self.webview loadHTMLString:html baseURL:[NSURL URLWithString:fullFilepath]];

如果这不起作用,请尝试更新从.zip文件获取的HTML文件的代码.就像是:

// Get the app Documents path

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,YES);

NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

// Add www/index.html to the basepath

NSError *err;

NSString *fullFilepath = [basePath stringByAppendingPathComponent:@"www/index.html"];

// Load the file,assuming it exists

NSString *html = [NSString stringWithContentsOfFile:fullFilepath encoding:NSUTF8StringEncoding error:&err];

// Check to ensure base element doesn't already exist

if ([html rangeOfString:@"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值