【问题标题】:Calling to https://itunes.apple.com/lookup?id is caching the json调用 https://itunes.apple.com/lookup?id 正在缓存 json
【发布时间】:2017-01-24 22:43:17
【问题描述】:

我在向https://itunes.apple.com/lookup?id=APPID 发出请求时遇到了一个非常奇怪的问题

如果我在浏览器中尝试此 url,它会为我提供应用程序的当前版本。但如果我从 iOS 应用程序调用它,它会给我旧的。

这是我正在使用的代码

let stringUrl : String = "https://itunes.apple.com/lookup?id=APPID"

    let req : NSMutableURLRequest = NSMutableURLRequest(url: URL(string: stringUrl)!, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 10.0)
    req.httpMethod = "get"

    let manager = AFHTTPRequestOperationManager()
    manager.responseSerializer = AFJSONResponseSerializer()

    let r = manager.httpRequestOperation(with: req as URLRequest!,
        success: { (operation: AFHTTPRequestOperation?,responseObject: Any?) in
            if let responseDic :Dictionary<String, AnyObject> = responseObject as? Dictionary<String, AnyObject> {

                let currentVersion: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String

                let results = responseDic.first?.value as! Array<AnyObject>

                let dic =  results.first as! Dictionary<String,AnyObject>
                let version : String = dic["version"] as! String
                //let version : String = responseDic.object(forKey: "results")?[0].object(forKey: "version") as! String

                self.isUpToDate = currentVersion == version

                delegate.onVersionReceived(version)
            }
        },
        failure: { (operation: AFHTTPRequestOperation?,error: Error?) in

    })
    r.start()

知道发生了什么吗?

【问题讨论】:

标签: ios swift app-store-connect nsmutableurlrequest


【解决方案1】:

Pablo Martinez wrote in a comment:

我认为是缓存。我在 url 中添加了一个随机参数,它解决了我的问题。

这也解决了我的问题。其他人绝对应该先尝试一下。

【讨论】:

  • 其实添加一个随机参数效果很好。
猜你喜欢
  • 2015-04-29
  • 1970-01-01
  • 1970-01-01
  • 2012-09-16
  • 2019-10-22
  • 1970-01-01
  • 2017-10-10
  • 2016-03-20
  • 1970-01-01
相关资源
最近更新 更多