Link to resources inside WebView - iPhone

前端 未结 10 1006
难免孤独
难免孤独 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:10

    OK, here 3.5 years later :) ... tried Michael Gaylord's suggestion above exactly, but it didn't work in sims for 5.0, 5.1, 6.0, 6.1 - nor in real devices running same. However this SO clarification on where resources are bundled ( Where is build output going? ) helped make it work for me like this:

    1. create a Finder folder in the project ( as Michael suggests - and I also did NOT try 'group')
    2. put your html in that folder using Finder
    3. in Xcode use file -> add files to project
    4. Make sure the project recognizes that it should be in the bundle by:

      1. Right click on main project target in Navigator window,
      2. make sure TARGETS is selected, the Build Phases tab,
      3. Click the Copy Bundle Resources triangle thingy |>
      4. And - here's what's different from Michael's - It should already show your html file AND the path. (Perhaps the XCoders have improved the add files AI :)

    So all I had to do was copy - paste Michael's code above verbatum and change this one line:

                         inDirectory:@"html"] 
    

    to:

                         inDirectory:nil]
    

    and Shaazam ! it worked :)

提交回复
热议问题