开发者

Why does UIWebView has problems with & characters in URL (wants &)

开发者 https://www.devze.com 2023-01-18 10:03 出处:网络
I have a problem with a UIWebView, that I use in my iPhone app. The source code shown in the UIWebView, contains the following markup besides many other things:

I have a problem with a UIWebView, that I use in my iPhone app. The source code shown in the UIWebView, contains the following markup besides many other things:

<object width="150" height="121"><param name="movie" value="http://www.youtube.com/v/SOMEVIDEO&hl=de&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/SOMEVIDEO&hl=de&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="150" height="121"></embed></object>

The UIWebView refuses to display the video the right way, because of the '&'-sign in the URL of the embedded object: http://www.youtube.com/v/SOMEVIDEO&hl=de&fs=1

If I replace the '&' with '&', everything shows like it should in the UIWebView. The same problem does not only occur at embedded videos, but also at regular URLs. The strange thing is, that the Safari-App displays the same website correctly, but not the UIWebView in my App. Am I missing something obvious here?

PS: The UIWebView shows an error-message on the top of the page, when trying to render with contents:

This page contains the following errors:
Error on line 102 at column 97: Entity Ref: expecting ';'
Below is a rendering of the page up to the first error.

Update for clarity:

I use this request to load the content:

[myWebView loadRequest:request];

That's why it is not possible to use -stringByAddingPercentEscapes method on NSString, like Jasarien suggested. It's about the whole 开发者_运维问答source, not single URLs.


This is because ampersands must be URL encoded to work in URLs. Same goes for spaces and other types of characters.

Check out the -stringByAddingPercentEscapes method on NSString.

0

精彩评论

暂无评论...
验证码 换一张
取 消