IPhone Open DATA: Url in Safari

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

data:text/html;base64,(Some Base64 Encoded Data Here) 
+9
url safari iphone data-url
Mar 13 '09 at 4:27
source share
2 answers

On iPhone OS 2.2.1 and 5.0.1, both in the simulator and on the device, when opening data: url works fine in UIWebView , but using openURL does exactly nothing.

And Safari will gladly and properly display such a URL if you want to enter it in the navigation bar, so this is clearly a problem with sharedApplication openURL , not Safari.

If the base64 string is short enough (maybe less than 2K), you can bind it as a request parameter to the http url, which simply returns a redirect to the data url. Then you can use openURL to open the http address. Yes, it means jumping over some server, but it will work.

Alternatively, since Safari obviously didn’t, you can tell iPhone that your application is a data schema processor : and be responsible for delivering content to UIWebView. However, this is likely to fail in the future. :-)

Where is the data url located first? Perhaps you can create a web page with a content of no more than <iframe src="<the data url>"/> and use OpenURL again at that URL.

+6
Mar 22 '09 at 3:29
source share

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.

-one
Mar 18 '09 at 21:55
source share



All Articles