Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

swift - NSURLErrorDomain with code=-1100

I was trying to download a picture to my app from

enter image description here The request failed with the error NSURLErrorDomain and the code is really -1100. The url should be correct since I checked it in the browser. Anyone knows why?

let userImageURL: String! = "http://i.imgur.com/QhCzQoR.jpg";
let url = NSURL(fileURLWithPath: userImageURL);
let request:NSURLRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: { (response:NSURLResponse!, imageData:NSData!, error:NSError!) -> Void in
                let image = UIImage(data: imageData!);
 })
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The reason you are getting this problem is because you have used

let url = NSURL(fileURLWithPath: userImageURL);

Instead you should use:

let url = NSURL(string: userImageUrl)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...