【发布时间】:2020-06-01 01:11:09
【问题描述】:
在这里,我尝试在 Safari 浏览器 中打开带有 .pdf 扩展名的 URL。但是代码不起作用我在URL 中得到了零。但是当我尝试像 "www.google.com" 之类的 URL 时,它工作正常
-
代码
let cerificateURl = "https://file-examples.com/wp-content/uploads/2017/10/file-sample_150kB.pdf" guard let url = URL(string: cerificateURl) else { return } if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url) }
提前致谢
【问题讨论】:
-
使用
addingPercentEncoding对URL进行编码。 -
您的字符串中有一个空格 "Rahul _"。如果你对它进行百分比编码,它应该可以工作。
.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)。您还需要将您的域添加到 info plist App Transport Security Settings Exception Domains 列表dropbox.com/s/hi684jdomlrl5r4/… -
如果你的服务器支持 https,你应该使用它