Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Open DATA: Url In Safari

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)
like image 411
Isaac Waller Avatar asked Mar 13 '09 04:03

Isaac Waller


People also ask

How do I enter a URL in Safari on iPhone?

Once Safari is up and running, there will be an Address Bar at the top of the screen. You can tap in the Address Bar to bring up the keyboard. From there you can key in the URL of the website that you want to go to.

Why some websites are not opening in Safari iPhone?

Connect to a different network If you don't have a mobile data connection, connect to a different Wi-Fi network, then load the website again. If you're using a VPN (Virtual Private Network), check your VPN settings. If you have a VPN turned on, some apps or websites may block content from being loaded.


1 Answers

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.

like image 186
ddoughty Avatar answered Sep 22 '22 19:09

ddoughty