iPhone Open DATA:在Safari中的URL

时间:2022-09-25 19:05:28

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:URL(参见:http://en.wikipedia.org/wiki/Data_URI_scheme)(作为NSString),我想在Safari中打开它。你将如何实现这一点(我试过openURL:。)示例:

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

2 个解决方案

#1


6  

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.

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

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.

如果您愿意在导航栏中键入一个URL,Safari很乐意并且正确地呈现这样的URL,因此这显然是sharedAppL openURL的问题,而不是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.

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

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

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

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.

数据URL首先来自哪里?也许您可以构建一个网页,其内容只不过是

#2


-1  

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.

假设“yourStr”是一个NString,其中包含数据所在的URL。

#1


6  

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.

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

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.

如果您愿意在导航栏中键入一个URL,Safari很乐意并且正确地呈现这样的URL,因此这显然是sharedAppL openURL的问题,而不是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.

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

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

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

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.

数据URL首先来自哪里?也许您可以构建一个网页,其内容只不过是

#2


-1  

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.

假设“yourStr”是一个NString,其中包含数据所在的URL。