清除在注销时缓存的图像

时间:2012-10-10 23:19:58

标签: objective-c ios ios5 ios-simulator cache-control

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

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]; 
} –

0 个答案:

没有答案