您好我正在下載JSON在我的應用程序與NSJSONSerialization的設備,似乎當我更新JSON文件並重新運行下載JSON函數它不下載新JSON。它只是下載非更新的JSON文件。我試過在不同的設備上運行應用程序,它第一次運行,但一旦我再次更新JSON,它不會下載新的JSON。我認爲它可能會被緩存,但我不確定。NSJSONSerialization沒有更新(可能獲得緩存)
這裏是我的代碼:
func downloadJSON(){
let p = NSURLRequest(URL: NSURL(string: "https://themartini.co/pythonStuff/quotey.json")!)
let sharedSession = NSURLSession.sharedSession()
let dwn = sharedSession.dataTaskWithRequest(p, completionHandler: { (data : NSData!,re : NSURLResponse!, error: NSError!) -> Void in
if error == nil {
let js : AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as NSArray // downloads JSON and puuts it into an array
println(js)
dispatch_async(dispatch_get_main_queue()){
self.quotes = js as NSArray
NSNotificationCenter.defaultCenter().postNotificationName("dataTaskFinished", object: nil)
}
}
})
dwn.resume()
}
任何想法?謝謝。
...你已經消除了中間CDN的原因是什麼?如何迅速,您在設備切換到設備?真正的解決將是讓你的服務器提供正確的緩存策略。 – Tommy 2014-12-04 00:49:03