URL(string:) returns nil 对于包含西里尔字母的路径
URL(string:) returns nil for a path that contains cyrillic
[NS]URL(string:) returns nil 对于包含西里尔字母的路径
https://somedomain.ru/upload/files/Оферта.pdf
10.15 中的 safari 打开 url 就好了。
有解决方法吗?
我是这样做的:
public extension URL {
static func open(urlString: String) {
guard let url = NSURL(string: urlString) else {
return
}
UIApplication.shared.open(url as URL)
}
}
永远不会达到 UIApplication.shared.open(url as URL)
(或者 UIApplication.shared.open(url) 如果我做 URL 而不是 NSURL
我想这两者是桥接的)
感谢 Daniel Storm 更新了解决方案:
static let оферта = "https://somesiteofours.ru/upload/files/" + ("Оферта.pdf".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "404")
...
您需要URL对路径进行编码:
https://somedomain.ru/upload/files/%D0%9E%D1%84%D0%B5%D1%80%D1%82%D0%B0.pdf
[NS]URL(string:) returns nil 对于包含西里尔字母的路径
https://somedomain.ru/upload/files/Оферта.pdf
10.15 中的 safari 打开 url 就好了。 有解决方法吗?
我是这样做的:
public extension URL {
static func open(urlString: String) {
guard let url = NSURL(string: urlString) else {
return
}
UIApplication.shared.open(url as URL)
}
}
永远不会达到 UIApplication.shared.open(url as URL) (或者 UIApplication.shared.open(url) 如果我做 URL 而不是 NSURL 我想这两者是桥接的)
感谢 Daniel Storm 更新了解决方案:
static let оферта = "https://somesiteofours.ru/upload/files/" + ("Оферта.pdf".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "404")
...
您需要URL对路径进行编码:
https://somedomain.ru/upload/files/%D0%9E%D1%84%D0%B5%D1%80%D1%82%D0%B0.pdf