ios - Display HTML file using UIWebView that has subdirectories and external js/img files -


in objective c, want display website have built using uiwebview.

brief overview: have folder has index.html. inside folder, there "img" folder , "js" folder. js folder has many .js files. img folder has many images. can run page independently (outside of xcode) no problem.

now able create basic html file, store in same directory of .h , .m files, , display correctly. goal display website subdirectories explained above.

here i've got far:

xcode:

- (void)viewdidload {     [super viewdidload];     nsstring *path = [[nsbundle mainbundle] path:@"index" oftype:@"html"];     nslog(path);     nsstring *content = [nsstring stringwithcontentsoffile:path encoding:nsasciistringencoding error:nil];     nsurl *baseurl = [nsurl fileurlwithpath:[[nsbundle mainbundle] bundlepath]];      [self.webview loadhtmlstring:content baseurl:baseurl]; } 

here file structure looks like:

enter image description here

when run it, build succeeds. nothing displayed. in addition, can check "issue navigator" tab (on left navigator) see list of issues. notice every .js file included in game.html file, there issue. state same thing:

dependency analysis warning: warning: no rule process file '$(project_dir)/web/gamefolder/js/input/mouseinputhandler.js' of type sourcecode.javascript architecture i386

so can do?

thanks: captainlonate

*dependency analysis warning: warning: no rule process file '$(project_dir)/web/gamefolder/js/input/mouseinputhandler.js' of type sourcecode.javascript architecture i386* 

after you've added html-related files project, *.js files added "compile sources" list in "build phases". compiler tried compile them, cannot, therefore warning (plus don't copied bundle). default behavior once cost me few minutes of exasperation...

remove them (*.js files) list , add "copy bundle resources"

another thing - in bundle, resources' hierarchy gets "flattened". mean, if had files that:

index.html js/lib/jquery.js img/circle.png 

you've had done like

<img src="img/circle.png"> 

but won't work in webview. you'll have referr same file that:

<img src="circle.png"> 

because webview sees files in bundle in way:

index.html jquery.js circle.png 

yet thing - load web content loading html file string , pass webview. it's not bad, believe it's bit better use other approach:

nsbundle* mainbundle = [nsbundle mainbundle]; nsstring* path = [mainbundle pathforresource: @"index" oftype: @"html"]; nsurl* url = [nsurl fileurlwithpath: path]; nsurlrequest* req = [nsurlrequest requestwithurl: url]; [webview loadrequest: req]; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -