0

This is my project structure:

image 0

I have 2 different View Controllers (GameViewController, TaskViewController). Both of them should be able to show a web view to the user.

  • The web view for GameViewController should load the file www/game/index.html

  • The web view for TaskViewController should load the file www/task/index.html

Adding the web view is quiet easy. But how can I specific the right path?

This was what I've tried inside the GameViewController:

let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "www/game") // not working

let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "game") // not working

let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "myApplication/www/game") // not working

How can I set the path for the files (with the same names [index.html] ) the right way?

Any help would be very appreciated. Thanks.

Jonas0000
  • 1,085
  • 1
  • 12
  • 36
  • You have to add the HTML files as "folder references" to your project, otherwise all files will be copied to the same directory in the application bundle. See for example https://stackoverflow.com/questions/6420925/load-resources-from-relative-path-using-local-html-in-uiwebview. – Martin R Feb 06 '18 at 13:16

1 Answers1

0

Try to add the files with references selected , suppose I have a folder named pp inside it there is a premium.txt when I drag it to Xcode selected create folder references and reference it easily with subdirectory, the folder will have a blue color

enter image description here

enter image description here

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • I've deleted my html-files and dragged them again into the folders. I've also enabled "create folder reference" but using this code: `let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "game")` will not work either. – Jonas0000 Feb 06 '18 at 13:25
  • game folder must contain index.html directly without inner subdirectories before you drag the folder to Xcode ???? – Shehata Gamal Feb 06 '18 at 13:29