iPhone Open DATA: Url In Safari

偶尔善良 提交于 2019-11-30 07:10:25
ddoughty

In iPhone OS 2.2.1 and 5.0.1, in both the simulator and on a device, opening a data: url works perfectly in a UIWebView but using openURL does precisely nothing.

And Safari will gladly, and properly, render such an URL if you are willing to type one into the navigation bar, so this is clearly a problem with sharedApplication openURL, not with Safari.

If the base64 string is short enough (less than 2K, probably) you could wrap it as a query parameter to an http URL that simply returns a redirect to the data url. Then you could use openURL to open the http URL. Yes, this means bouncing through some server, but it would work.

Alternatively, since Safari obviously hasn't done it, you could tell the iPhone that your app is the handler for the data: scheme and take responsibility for rendering the content in a UIWebView. This seems likely to fail in the future, though. :-)

Where is the data URL coming from in the first place? Perhaps you could construct a web page whose contents are nothing more than <iframe src="<the data url>"/> and again, use openURL on that URL.

This should do it:

NSURL *yourURL = [[NSURL alloc] initWithString:yourStr];    
[[UIApplication sharedApplication] openURL:yourURL];
[yourURL release];

assuming "yourStr" is an NString with the URL where your data is located.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!