Swift shardApplication().openURL() with data URI

时间:2016-03-04 18:21:13

标签: swift nsurl data-uri openurl data-uri-scheme

So I have a String with the template of

let dataURI = 'data:MIMEType;base64,DATA'

where the data is filled with a bunch of base64 representing the file I want to open. This url will load in a WKWebView or UIWebView; however, when I try to take the same URL and open it via

let uri = NSURL(string: dataURI)
UIApplication.sharedApplication().openURL(uri)

I get the error

LaunchServices: ERROR: There is no registered handler for URL scheme data

I also attempted a string with the format of

let uristring = 'data://' + dataURI 

which gets the same error.

Any ideas whats going on here?

Thanks!

1 个答案:

答案 0 :(得分:1)

iOS仅包含一些网址计划的处理程序(特别是httpmailtotelsms)。不幸的是,它没有对data方案的内置支持。因此,操作系统不知道它可以将您的数据传递给Safari进行显示。

您可以找到有关应用内通信here的更多信息以及iOS here原生支持的所有方案。