kCLErrorDomain iOS请求被中断sock = client heroku

时间:2015-04-04 18:31:12

标签: ios django swift heroku

我有一个使用django在heroku上托管的后端,我有一个消费该API的iOS应用程序。有时应用程序会抛出此错误

locman err:  Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

同一请求的后端会抛出此错误

sock=client at=error code=H18 desc="Request Interrupted" status=503

我应该如何在iOS中处理此问题?这似乎是应用程序的一个问题。我只是一次发出太多请求吗? 继承人我的api控制器看起来像什么

class func getPictures(location_id: String, completionHandler:( cardImageArray: [CardImage] )->() ){


    var bodyString: String = "location_id=\(location_id)"
    bodyString = bodyString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!


    let url: NSURL = NSURL(string: BASE_URL + "/api/v1/get_pictures" + "?" + bodyString)!

    let req: NSMutableURLRequest = NSMutableURLRequest(URL: url)
    req.HTTPMethod = "GET"
    //req.HTTPBody = bodyString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)

    NSURLConnection.sendAsynchronousRequest(
        req,
        queue: NSOperationQueue.mainQueue())
        { (res: NSURLResponse!, data: NSData! , err: NSError!) -> Void in
            let jsonDict = JSON(data: data, options: NSJSONReadingOptions.AllowFragments, error: nil)

            if (jsonDict["response"].int == 1){

                var cardImageArray: [CardImage] = []

                if let photo_urls = jsonDict["photo_urls"].array{

                    //                        NSString(data: data, encoding: nil)

                    for photo_url_raw in photo_urls{

                        if let url_string = photo_url_raw.string{
                            let ci = CardImage(urlstring: url_string)
                            cardImageArray.append(ci)
                        }


                    }

                    return completionHandler(cardImageArray: cardImageArray)

                }


            }else{

                println("error in get pictures")

                if let errorMessage = jsonDict["error"].string{
                    return
                }

            }
    }
}

1 个答案:

答案 0 :(得分:0)

当位置管理员无法确定用户位置时,这就是打印的错误消息。刚刚处理了错误并让用户点击按钮再试一次。