Remote image doesn't get displayed in html pag

2020-04-11 14:13发布

问题:

The following code

<a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=156093464&id=156093462&s=143441">
<img height="15" width="61" alt="Randy Newman - Toy Story
- You&#39;ve Got a Friend In Me" src="http://ax.phobos.apple.com.edgesuite.net/images/
badgeitunes61x15dark.gif"></img>
</a>

Is from apple's documentation

http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/iTunesLinks.html#//apple_ref/doc/uid/TP40007896-SW1

When a html page containing that href is loaded into a browser the image is displayed, however when its loaded into a UIWebView it isn't displayed.

ShouldStartLoadWithRequest: does not get called for the following URL

http://ax.phobos.apple.com.edgesuite.net/images/
badgeitunes61x15dark.gif

Why does it not get called and why does this work in a browser but not in UIWebView?

回答1:

Well, I just built a prototype with your HTML, and it worked fine for me.

However, a few thoughts:

  • First, if you implement webView:shouldStartLoadWithRequest:navigationType: in your web view delegate, don't expect a callback for every single item in your HTML page. If I remember correctly, it only calls that for top level requests (e.g. the whole page). So, I would not expect to get a callback just for that one img resource.

  • Since we already established that implementing webView:shouldStartLoadWithRequest:navigationType: won't do what you want, you might want to remove it altogether. When I first lazily put it in my code, I forgot to return YES; from that method. Since Objective-C is a rather loose language, the app built and ran, but obviously took NO to be the implicit return value from that method. NO stops the request from loading. If the image was the only thing in a sample page you had, you wouldn't see anything (and maybe falsely think it was just because of the img itself).

  • I can't tell if this is only in the HTML that you posted in your question, or if it's in the real code, too. But, you have whitespace inside your img src URL, after "images/". That would obviously make this break.

  • In my test, I also started with a web page that didn't scale content to fit. That image is rather small, so if you don't scale your web view to fit, and view it on an iPhone/iPod, you might not have noticed such a small image.

    webview.scalesPageToFit = YES;

Anyway, that's all I can think of. Like I said, it works for me. It's not the image itself, or any difference between Mobile Safari, vs. UIWebView.

Double check and report back :)



标签: ios uiwebview