iOS创建自己本地缓存目录,截图图片存储失败问题
程序员文章站
2022-06-14 15:23:03
...
1. 创建自定义目录时,fileExistsAtPath 必须判断是文件目录
/**
get absolute iamge cache path
@param imageName file name
@return absolute path
*/
+ (NSString *)getAbsoluteImageCachePath:(NSString *)imageName {
NSString *appPackageName = [APP_INFO_DICT objectForKey:@"CFBundleIdentifier"];
NSString *md5ImageName = [self cachedFileNameForKey:imageName];
NSString *adShowImageDiskPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true) firstObject];
NSString *adShowImageDiskDir = [adShowImageDiskPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/CZFAdShowImages/", appPackageName]];
adShowImageDiskPath = [adShowImageDiskDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", md5ImageName]];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:adShowImageDiskDir]) {
NSError *error;
[fileManager createDirectoryAtPath:adShowImageDiskDir withIntermediateDirectories:YES attributes:nil error:&error];
if (error) {
NSLog(@"create directory error:%@", error.description);
}
}
return adShowImageDiskPath;
}
上一篇: 《联系人管理》小案例
下一篇: Ajax在请求过程中显示进度的简单实现