当我们在使用URL的时候,发现,地址有值,但是,生成URL的时候URL 为 nil,这是 str 中有中文字符串,故不能直接使用,需要转换一下即可!
let str = "\(BaseUrlHttp)\(urlString!)"
let charSet = CharacterSet.urlQueryAllowed as NSCharacterSet
let mutSet = charSet.mutableCopy() as! NSMutableCharacterSet
mutSet.addCharacters(in: "#")
let encodingURL = str.addingPercentEncoding(withAllowedCharacters: mutSet as CharacterSet)
guard let url:URL = URL(string: encodingURL!) else { return }
myWkWebView.load(URLRequest(url:url))
网友评论