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

清除缓存的代码如下:

// 清理缓存
    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)
阿神

最初にパスが有効かどうかを確認してください。絶対パスまたは相対パスを取得しましたか?
2 番目
NSString *path = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",p]];
このように stringByAppendingPathComponent を使用するのが最善です

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!