NSURLSession数据始终为零字节

时间:2015-04-11 20:17:09

标签: ios swift

我发誓它前几天正在工作,现在我在响应中将数据作为零字节获取。结果变量为空。我被Flickr API阻止了吗?

这是我的代码:

func setup() {

    let flickrURL = "http://api.flickr.com/services/feeds/photos_public.gne?tags=texas&tagmode=any&format=json&jsoncallback=?"

    let session = NSURLSession.sharedSession()

    (session.dataTaskWithURL(NSURL(string :flickrURL)!, completionHandler: { (data :NSData!, response, error) -> Void in

        let result = NSString(data: data, encoding: NSUTF8StringEncoding)

        // convert result into JSON dictionary 
      //  NSJSONSerialization.JSONObjectWithData(data, options:nil, error: nil) as NSDictionary

        println("\(result!)")



    })).resume()

}

以下是错误参数中存储的内容:

Printing description of error.Some:
Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x7fde2da8f390 {NSErrorFailingURLStringKey=http://api.flickr.com/services/feeds/photos_public.gne?tags=texas&tagmode=any&format=json&jsoncallback=?, NSErrorFailingURLKey=http://api.flickr.com/services/feeds/photos_public.gne?tags=texas&tagmode=any&format=json&jsoncallback=?, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x7fde2da63430 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}

1 个答案:

答案 0 :(得分:0)

重新启动模拟器应解决此问题。