0

我在缓存中创建了一个图像,如下所示:

NSURL *cachesDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject]; // iOS Caches directory

NSURL *profilePictureCacheURL = [cachesDirectoryURL URLByAppendingPathComponent:@"FacebookProfilePicture.jpg"];

BOOL cachedToDisk = [[NSFileManager defaultManager] createFileAtPath:[profilePictureCacheURL path] contents:newProfilePictureData attributes:nil];

NSLog(@"Wrote profile picture to disk cache: %d", cachedToDisk);

UIImage *image = [UIImage imageWithData:newProfilePictureData];

UIImage *mediumImage = [image thumbnailImage:280 transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationHigh];
UIImage *smallRoundedImage = [image thumbnailImage:64 transparentBorder:0 cornerRadius:9 interpolationQuality:kCGInterpolationLow];

NSData *mediumImageData = UIImageJPEGRepresentation(mediumImage, 0.5); // using JPEG for larger pictures
NSData *smallRoundedImageData = UIImagePNGRepresentation(smallRoundedImage);

我应该在另一种方法(用于注销)中添加什么来从缓存中清除此图像?

试过这个,它没有工作:

// Clear the cached profile and other images in cache 
NSFileManager *fileMgr = [NSFileManager defaultManager]; 
NSString *cachesDirectoryURL = [[[NSFileManager defaultManager]    URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];

// iOS Caches directory 
NSArray *fileArray = [fileMgr contentsOfDirectoryAtPath:cachesDirectoryURL error:nil]; 
for (NSString *filename in fileArray) 
{ 
  [fileMgr removeItemAtPath:[cachesDirectoryURL stringByAppendingPathComponent:filename] error:NULL]; 
} –
4

0 回答 0