ios NSURLErrorDomain 错误代码 1002 说明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26647423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSURLErrorDomain error code 1002 description
提问by sasquatch
I am new to iOSdevelopment. I am trying to load a JSON, here's my function:
我是iOS开发的新手。我正在尝试加载JSON,这是我的功能:
func loadmyJSON (urlPath: String) {
let url: NSURL = NSURL(string: urlPath)!
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
println("Task completed")
if(error != nil) {
// If there is an error in the web request, print it to the console
println("error not nil::::::")
println(error.localizedDescription)
}
var err: NSError?
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
if(err != nil) {
// If there is an error parsing JSON, print it to the console
println("JSON Error \(err!.localizedDescription)")
}
let results: NSArray = jsonResult["variants"] as NSArray
dispatch_async(dispatch_get_main_queue(), {
self.jsonTable = results
self.productView!.reloadData()
})
})
But I am getting this error:
但我收到此错误:
error not nil::::::
The operation couldn't be completed. (NSURLErrorDomain error -1002.)
error not nil::::::
The operation couldn't be completed. (NSURLErrorDomain error -1002.)
I am able to get the JSON in the browser through the same URL. I have tried reading this Apple Doc, but I can't get the description.
我能够通过相同的 URL 在浏览器中获取 JSON。我曾尝试阅读此 Apple Doc,但无法获得说明。
What does this error code mean?
这个错误代码是什么意思?
回答by Asif Asif
NSURLErrorDomain error -1002
means NSURLErrorUnsupportedURL
or kCFURLErrorUnsupportedURL
. It indicates that a bad URL was provided, in most cases, missing http://
from the URL prefix.
NSURLErrorDomain error -1002
意味着NSURLErrorUnsupportedURL
或kCFURLErrorUnsupportedURL
。这表明提供了错误的 URL,在大多数情况下,http://
URL 前缀中缺少该 URL。
The list of all NSURLErrorDomain
codes can be found here: https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes
所有NSURLErrorDomain
代码的列表可以在这里找到:https: //developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes
回答by Kunal Gupta
In addition to the above answer, one of the reasons why this could happen is,
除了上述答案之外,可能发生这种情况的原因之一是,
You might have set the Allow Arbitrary Loadsto false
in your Info.plist and the URL you are trying to load is not on a secured server.
您可能在 Info.plist 中设置了Allow Arbitrary Loads,false
并且您尝试加载的 URL 不在安全服务器上。
The solution to this is either set it to true
, or move to a secure connection i.e https://
.
对此的解决方案是将其设置为true
,或移动到安全连接,即https://
。
Hope it helps someone. All the best.
希望它可以帮助某人。祝一切顺利。
回答by Gurjinder Singh
I encounter the same issue and found that keyparameter was missing from URL. You need to set Google map keyvalue for key parameter in URL you are using to make request. This can be occur if you are missing other keys.
我遇到了同样的问题,发现URL 中缺少关键参数。您需要为用于发出请求的 URL 中的关键参数设置Google 地图键值。如果您缺少其他键,就会发生这种情况。