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