How to disable caching from NSURLSessionTask

后端 未结 7 607
终归单人心
终归单人心 2020-12-04 23:24

In my iOS app, I am using NSURLSessionTask to download json data to my app. I discovered that when I call the url directly from the browser, I get an up to date

相关标签:
7条回答
  • 2020-12-05 00:21

    Swift 4 & 5

    I know it's been a while, but in case it might help someone in the future.

    You may also use .ephemeral configuration property of URLSession, which doesn't save any cookies and caches by default.

    As documentation goes,

    An ephemeral session configuration object is similar to a default session configuration, except that the corresponding session object doesn’t store caches, credential stores, or any session-related data to disk. Instead, session-related data is stored in RAM.

    So, your code might look like this:

    let configuration = URLSessionConfiguration.ephemeral
    let session = URLSession(configuration: configuration)
    
    0 讨论(0)
提交回复
热议问题