How to Clear IOS App Library Cache (Downloaded Images)

后端 未结 1 1424
夕颜
夕颜 2021-01-16 12:04

I am working with download async images. I get a lot images from my webserver but all are temporary and I won\'t cache any of them. But the app apparently save the download

1条回答
  •  醉梦人生
    2021-01-16 12:36

    The cache will be emptied when it needs to be, i.e. when the application receives a Low Memory Warning. There is no reason for you to do this yourself, and there is no public API available.


    NOTE
    When the os manages something for you, you don't need to worry about it.


    But if you really want to clear your cache then follow this

    NSFileManager *filemgr;
    
    filemgr = [NSFileManager defaultManager];
    
    if ([filemgr removeItemAtPath: [NSHomeDirectory() stringByAppendingString:@"/Library/Caches"] error: NULL]  == YES)
        NSLog (@"Remove successful");
    else
        NSLog (@"Remove failed");
    
    [filemgr createDirectoryAtPath: [NSHomeDirectory() stringByAppendingString:@"/Library/Caches"] withIntermediateDirectories:NO attributes:nil error:nil];
    

    0 讨论(0)
提交回复
热议问题