开发者

How can I link in both remote and local assets into a webview?

I'm loading HTML-formatted content into my app from a web service, then plugging that into a local HTML template that lives within the app. Now, I need to set the UIWebView's BaseURL to point at the remote server so that all relative image links will load. However, I'm also trying to link in some local assets (CSS, JavaScript). Thus far, I have not found any documentation on how to link in local ass开发者_开发知识库ets without relying on the UIWebView's baseURL. I've tried injecting the absolute file path of my CSS and JS into my HTML template, but it hasn't worked... I don't know if that means that it doesn't work, or if I'm just doing it wrong.

Has anyone ever run into this scenario, and if so, how did you address it? Thanks in advance, I really appreciate any tips!


How are you injecting the local path? My approach would be:

NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"script" ofType:@"js"];
NSURL *url = [NSURL fileURLWithPath:pathToFile];
NSString *injectString = url.absoluteString;

Although, I couldn't tell you if this actually works or not, since I have never tried it. The other option is to instead use the local path as the base URL, and inject the remote path for files instead. I'm not sure how your HTML is formatted, or what changes you'd have to make to do it that way, but that would much more likely work if this approach does not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜