【发布时间】:2015-12-09 18:15:17
【问题描述】:
您好,我正在使用 WebView 从字符串中加载特定 URL,但在 WebView 中,但它返回为 nil。
var linkobject = "http://prf.hn/click/camref:1011l62a/creativeref:1100l4014/destination:http://nl.tommy.com/Tommy-Cares-Tas/C827884386,nl_NL,pd.html#!i=0&color=000&size=OS&utm_source=performancehorizon&utm_medium=affiliate&utm_campaign=FW15&utm_term=(UserID)&utm_content=feed&cmpid=ch:affiliate|dp:ecom|so:performancehorizon|cp:fw15|co:uk|pi:(UserID)|cr:feed&LGWCODE=8718937448230;88093;5350?LGWCODE=8718937448230;105153;6183"
if let url = NSURL(string:linkobject) {
var req = NSURLRequest(URL: url)
if count(url.description) != 0 {
self.webView.contentMode = UIViewContentMode.ScaleAspectFit
self.webView.loadRequest(req)
}
}
现在我已经阅读了官方文档中的这个 url 不适用于 RFC 2396 标准,这就是为什么它给了我一个 nil 对象。
如果传递的路径格式不正确,则 NSURL 类无法创建新的 NSURL 对象;路径必须符合 RFC 2396
有人知道我如何在我的 webview 中加载这种类型的 url,或者以任何方式绕过或覆盖 NSURL,以便我的字符串可以转换为 NSURL?喜欢听取建议,修改网址不是一种选择,因为它是作为附属网址提供的。
【问题讨论】:
-
返回 nil 的那一行
标签: ios swift uiwebview nsurl nsurlrequest