views:

27

answers:

1

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&amp;hl=de&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/SOMEVIDEO&amp;hl=de&amp;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&amp;hl=de&amp;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.

+2  A: 

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.

Jasarien
But the problem is, getting at the simple URL-string. I am getting the whole website source-code, and if I percent-escapes the whole website source-code, than other parts would be mess up again...To be clear, I use this line, to load the content into UIWebView: [myWebView loadRequest:request];
nodepond
Perhaps you should mention that in your question? The way it currently is implies that the html is within the iPhone app.
Jasarien