Link to resources inside WebView - iPhone

前端 未结 10 979
难免孤独
难免孤独 2020-11-27 14:28

I have a webview in my iPhone application, and I also have some html files inside my Resources folder. When my app loads, I load in a page from my resources into my webview.

相关标签:
10条回答
  • 2020-11-27 15:27

    Maybe it does have something to do with the baseurl: when I load the resources, I use this line:

    [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
    

    see at the end, it says baseURL: "". If I take this out, it doesn't work (crashes), but I don't know the path to my resources. If somebody does.....?

    0 讨论(0)
  • 2020-11-27 15:30

    Try loading OtherPage.html first. If you can't then it's not there, and you've missed some part of adding it to the project. If you can, then there may just be a typo in the link, or the baseURL could be incorrect, as stated by August. When I created an html file with images in it that were in the resource file, it worked fine just using

    <img src="file.png">
    
    0 讨论(0)
  • 2020-11-27 15:30

    Take a look at how Phonegap does it. Here's their tutorial on local resources on the iPhone. Step 11 might be what you're neglecting.

    0 讨论(0)
  • 2020-11-27 15:33

    I fixed it: I used this for the BaseURL like August said:

    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    

    Thank you!

    0 讨论(0)
提交回复
热议问题