美文网首页
webView加载不同资源

webView加载不同资源

作者: 紫嫣沁 | 来源:发表于2021-09-05 20:57 被阅读0次

1,loadRequest:

加载网络资源:

[webView loadRequest:[NSURLRequest  requestWithURL: [NSURL URLWithString:urlStr]]];

这个地址是网络地址,或者网络地址拼接自己的地址,如:

NSString* urlStr = @"http://bestpay.ctdns.net/u1/mepf/mems/html/agreement/" ;

urlStr = [urlStr stringByAppendingPathComponent : AgentForSettlement.html] ;

2,loadHTMLString:

加载本地的html文件

[webView loadHTMLString : [[NSBundle mainBundle] pathForResource:@" AgentForSettlement " ofType:@"html"]; baseURL : [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

安全一点把string进行UTF8转码一下

NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

相关文章

网友评论

      本文标题:webView加载不同资源

      本文链接:https://www.haomeiwen.com/subject/rfttuxtx.html