我创建了一个应用程序,我将从服务器下载图像并将其本地存储在 iPhone 的文件系统中。它发生的很好。现在的问题是,当我退出我的应用程序时,我想清除 iPhone 上本地缓存的图像。
我如何删除 iPhone 上的那些缓存图像。它在 iPhone 上使用辅助内存,我如何以编程方式访问它?
提前谢谢你。 苏斯。
最佳答案
在您的 applicationWillTerminate 方法中清除它们。
- (void)applicationWillTerminate:(UIApplication *)application
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *imagesFiles = [fileManager contentsOfDirectoryAtPath:saveDirectory error:&error];
for (NSString *file in imagesFiles) {
error = nil;
[fileManager removeItemAtPath:[saveDirectory stringByAppendingPathComponent:file] error:&error];
/* do error handling here */
}
}
https://stackoverflow.com/questions/5403004/