objective-c - iOS开发,清除缓存功能在iOS8上有效,在iOS9和10上无效
怪我咯
怪我咯 2017-04-18 09:43:28
0
1
550

清除缓存的代码如下:

// 清理缓存
    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath];
    NSLog(@"文件数 :%ld",[files count]);
    for (NSString *p in files)
    {
        NSError *error;
        NSString *path = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",p]];
        if([[NSFileManager defaultManager] fileExistsAtPath:path])
        {
            [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
        }
    }

在iOS8上可以清理缓存,在iOS9 和 iOS10上无效。

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回覆(1)
阿神

先確認一下路徑是否有效!你拿到的是絕對路徑還是相對路徑?
其次
NSString *path = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",p]];
最好使用 stringByAppendingPathComponent 這個方式

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!