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

Discussion in 'iOS Programming' started by moonman239, Apr 11, 2015.

  1. moonman239, Apr 11, 2015
    Last edited: May 27, 2015

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    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.
     
  2. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #2
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    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.
     
  4. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #4
    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?"
     
  5. moonman239, May 21, 2015
    Last edited: May 21, 2015

    moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #5
    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:

     
  6. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #6
    OK, changed baseURL to the URL of the parent directory of the racecar.html file. Didn't help. Will someone please help me?

    Thanks!
     
  7. moonman239, May 26, 2015
    Last edited: May 26, 2015

    moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #7
    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.
     
  8. recoil80 macrumors 68000

    Joined:
    Jul 16, 2014
    #8
    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.
     
  9. firuz1844 macrumors newbie

    firuz1844

    Joined:
    Oct 14, 2016
    #9
    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.
     

Share This Page