Resolved WKWebView not showing images on iPad - how to fix?

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,521
22
I don't understand. My WebKit view is supposed to display a racecar going around a track. It does just that on the simulator, but on an iPad I just see the green background. Do I need to create a UIView and put the WebKit view in there?

Edit: I suppose I should add that the content is generated using JavaScript. You see, what I wanted to do was create the animation using Adobe Flash Professional, then port it to iOS. Exporting the animation to HTML5 seemed like the way to go about doing that.

Edit: Copying and pasting all the JavaScript from the external JS files into the HTML file solved the problem.
 
Last edited:

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Does your baseURL point to those .js files? The web view needs to be able to find them.

Also, baseURL should probably be a folder, not a path to a file.
 

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,521
22
Does your baseURL point to those .js files? The web view needs to be able to find them.

Also, baseURL should probably be a folder, not a path to a file.
My base URL points to the HTML page that's in charge of the animation, and it is in the same folder as the libs folder (where all my JS files are)

I'll change the base URL and see what happens. My question still is, "why would it work on the simulator but not on the device?"
 

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,521
22
Tried that, didn't help. Tried moving files into the app folder within the project, didn't help. I'm about ready to try singing an incantation.

Edit: I threw a try-catch block into my HTML file, around a piece of code that uses an object that is declared in one of the JS files. If the code causes an exception, then it is programmed to send my application a message with the exception's message. The app is programmed to display this message in my logs.

Well, I ran the app again, and such a message was sent. Here's what it says:

Exception: undefined is not a constructor (evaluating 'new lib.racecar()')
 
Last edited:

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,521
22
OK, changed baseURL to the URL of the parent directory of the racecar.html file. Didn't help. Will someone please help me?

Thanks!
 

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,521
22
JavaScript files won't load because of WKWebView bug

OK, so I did some Googling and found this comment page: https://disqus.com/home/discussion/initlabs/wkwebview_vs_uiwebview/

Turns out that there's a bug in WKWebView that causes the Web view to not load any external resources, such as JavaScript files, that are mentioned in an HTML file.

Do any of you have a workaround? The only other way I can think of is to use a UIWebView instead of a WKWebView, but I don't want to.

Edit: I just copied all the JavaScript into my racecar.html file. The animation should work now, although I haven't tried it.
 
Last edited:

recoil80

macrumors 68030
Jul 16, 2014
2,540
2,104
I'm having a similar problem with images in the Library directory
My HTML and JS are loaded correctly, but if I put the full path of an image in the src attribute of an image it works only on the simulator.
The problem may be related to the fact that the path is full and I may solve it with relative paths, but my HTML are into the bundle and I don't want to mess with ../../../ etc to reach Library from a bundle path, nor I want to copy my HTML and JS to the Library to be able to refer to images with a relative path, it seems like a waste of resources. I may try with symbolic links, but since I'm supporting iOS 8 I'm afraid I may be forced to come up with a solution for the JS loading as well, so goodbye WKWebView.
I switched back to UIWebView and of course everything works like a charm.
 

firuz1844

macrumors newbie
Oct 14, 2016
3
0
I don't understand. My WebKit view is supposed to display a racecar going around a track. It does just that on the simulator, but on an iPad I just see the green background. Do I need to create a UIView and put the WebKit view in there?

Edit: I suppose I should add that the content is generated using JavaScript. You see, what I wanted to do was create the animation using Adobe Flash Professional, then port it to iOS. Exporting the animation to HTML5 seemed like the way to go about doing that.

Edit: Copying and pasting all the JavaScript from the external JS files into the HTML file solved the problem.
It'is known WKWebView bug (or Apple's new feature, I am not sure :)) but here is known workaround http://stackoverflow.com/a/28676439/2514012.

In two words - use -loadFuleUrl:allowingReadAccessToUrl: instead of -loadHTMLSting:baseUrl: or whatever you use.