iPhone Open DATA:在Safari中的URL [英] iPhone Open DATA: Url In Safari

查看:197
本文介绍了iPhone Open DATA:在Safari中的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据:网址(请参阅: http://en.wikipedia.org/wiki/ Data_URI_scheme )(作为NSString),我想在Safari中打开它。你会如何做到这一点(我试过openURL:。)

示例:

I have a Data: URL (see: http://en.wikipedia.org/wiki/Data_URI_scheme) (as a NSString) and I want to open it in Safari. How would you accomplish this (I tried openURL:.)
Example:

data:text/html;base64,(Some Base64 Encoded Data Here)


推荐答案

In iPhone OS 2.2.1和5.0.1,在模拟器和设备上,打开数据: url在 UIWebView 中完美运行但是使用 openURL 确实没有任何作用。

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.

如果你愿意,Safari会很乐意,并且正确地呈现这样的URL在导航栏中键入一个,所以这显然是 sharedApplication openURL 的问题,而不是Safari。

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.

如果base64字符串足够短(可能小于2K),您可以将其作为查询参数包装到http URL,该URL只返回重定向到数据URL。然后,您可以使用openURL打开http URL。是的,这意味着通过一些服务器弹跳,但它会工作。

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.

或者,因为Safari显然没有这样做,你可以告诉您的应用程序的iPhone是 data:方案的处理程序,并负责在UIWebView中呈现内容。不过,这似乎在未来可能会失败。 : - )

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. :-)

首先来自哪里的数据网址?也许您可以构建一个网页,其内容只不过是< iframe src =< the data url>/> 并再次在该网址上使用openURL 。

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.

这篇关于iPhone Open DATA:在Safari中的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆