Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios8 UIWebview svg embaded html not show

I am recently working on a svg map app. everything is running fine on ios7. when i move my project to ios8. strange things happened, I found when UIWebview read local html file which has a svg file embedded, the svg file will not shown on ios8.

sample code is here:

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path];
NSURLRequest *req = [NSURLRequest requestWithURL:fileURL];
[self.webView loadRequest:req];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end

and the html file used:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>SVG DEMO</title>
</head>
<body>
<div>
    <embed src="410.svg" width="64" height="64" type="image/svg+xml" />
    <object type="image/svg+xml" data="410.svg" width="64" height="64" border="1"></object>
</div>
</body>
</html>

Does anyone know what's going on?

Thanks

like image 614
Liu Yale Avatar asked Sep 18 '14 05:09

Liu Yale


2 Answers

I had the same problem with my application. And I found this solution:

<!DOCTYPE html>
<html>
    <head>
        <title>Informations</title>
    </head>
    <body>
        <center><img src="logo.svg" width="200" height="200" /></center>
    </body>
</html>

Works with iOS 7.0.3 and 8.0

like image 126
jbejean Avatar answered Oct 13 '22 16:10

jbejean


I noticed that SVGs that had an animate tag showed up fine, while those without did not show up. Adding a dummy animate tag to the svg is the workaround I'm using for the time being.

...
<animate attributeName="opacity" values="0.99;1.0" dur="0.01s" begin="0s" repeatCount="1"></animate>
</svg>

Update:

This issue is fixed in iOS 8.1.2 (possibly earlier), so this is no longer needed.

like image 42
tarun2000 Avatar answered Oct 13 '22 17:10

tarun2000