0

I successfully load plist from URL server, but cache holds old data. Here is my code to load plist, how can I implement NSURLRequest to clear old cache data? Or do I need to try another approach?

This question partially answer this problem: https://stackoverflow.com/questions/11235883/downloading-plist-but-seem-to-get-a-cached-version-every-time#=

NSString *stringURL = @"https://web.com/myPlist.plist";

NSURL  *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths objectAtIndex:0];
NSString  *plistPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"myPlist.plist"];
[urlData writeToFile:plistPath atomically:YES];
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Don't use `[NSData dataWithContentsOfURL:]`. Use `NSURLSession` and `NSURLSessionDataTask`s instead, and the set `cachePolicy` for your requests. – Gereon Aug 09 '19 at 18:27
  • Thx. i will try that. –  Aug 10 '19 at 05:55

0 Answers0