views:

161

answers:

2

I've got a simple UIWebView in my iPhone app that's loading a XHTML document with some SGV embeded. This all works find on the desktop version of Safari, but it crashes in a UIWebView.

Here is the Objective C:

NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSData *fileData = [NSData dataWithContentsOfFile: path];
[svgView loadData: fileData MIMEType: @"text/xml" textEncodingName: @"UTF-8" baseURL: [NSURL fileURLWithPath: path]];

I also tried a MIMEType of application/xhtml+xml, but it didn't help.

Here is the HTML:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"&gt; 
<head> 
  <title>XTech SVG Demo</title> 
</head> 
<body> 
<svg xmlns="http://www.w3.org/2000/svg"&gt; 
  <g style="fill-opacity:0.7;"> 
    <circle cx="6.5cm" cy="2cm" r="100" style="fill:red; stroke:black; stroke-width:0.1cm" transform="translate(0,50)" /> 
    <circle cx="6.5cm" cy="2cm" r="100" style="fill:blue; stroke:black; stroke-width:0.1cm" transform="translate(70,150)" /> 
    <circle cx="6.5cm" cy="2cm" r="100" style="fill:green; stroke:black; stroke-width:0.1cm" transform="translate(-70,150)"/> 
  </g> 
</svg>
</body> 
</html> 

All very basic stuff. When it loads on the iPhone, however, it crashes with this error:

2010-03-31 10:37:10.252 ColorDoodle[2014:20b] -[DOMElement structuralComplexityContribution]: unrecognized selector sent to instance 0x3e51b60 2010-03-31 10:37:10.253 ColorDoodle[2014:20b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[DOMElement structuralComplexityContribution]: unrecognized selector sent to instance 0x3e51b60'

Any idea why? Is this a bug in the rendering engine of the UIWebView? I don't see anything too odd here.

* Updated *

There is definitely something screwy going on here.

If I add this bit of code just inside the tag, it works fine:

<form>
</form>

Take that code back out, and it crashes again.

A: 

Looks like a bug in WebKit. Should not happen. File it.

St3fan
I did submit it to Apple, thanks.Unfortunately, that means my app can't run on any current device, and will only work with the next release of the iPhone OS. And, everyone will need to upgrade to it... Ugh.
Axeva
A: 

I've just been struggling with this. Adding <form></form> tags has made no difference for me, and the bug persists at least up to OS 3.1.3, judging by my tests in the iPhone Simulator.

However, I've found a simple workaround, which is to display the SVG markup within <img /> tags, using a data: URI for the src attribute.

You can Base64- or URL-encode the SVG markup. Unsurprisingly, it gzips better when URL-encoded. (In fact, if you serve the HTML as text/html, you can seemingly get away without encoding the SVG at all, as long as you don't end the src attribute with the wrong kind of quote mark inside the SVG.)

jawj