- (NSString *) dataPath{
NSArray *storeFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *doucumentsDirectiory = [storeFilePath objectAtIndex:0];
return [doucumentsDirectiory stringByAppendingPathComponent:[NSString stringWithFormat:@"/ImageSave"]];
}
-(void)creatFileAndWriteDataTOFile {
//判断目录是否存在
if(![[NSFileManager defaultManager] isExecutableFileAtPath:[self dataPath]]) {
NSLog(@"create");
//创建目录
[[NSFileManager defaultManager] createDirectoryAtPath:[self dataPath]withIntermediateDirectories:YES attributes:nil error:nil];
}
if(![[NSFileManager defaultManager] isExecutableFileAtPath:[NSString stringWithFormat:@"%@/%@",[self dataPath],setting._NowSN]]) {
NSLog(@"create");
//创建目录
[[NSFileManager defaultManager] createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@",[self dataPath],setting._NowSN]withIntermediateDirectories:YES attributes:nil error:nil];
}
NSDate *selected = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"/yyyyMMddHHmmss"];
NSData *imageData = nil;
imageData = UIImagePNGRepresentation(theImage);
//写数据到指定的路径
[imageData writeToFile:[NSString stringWithFormat:@"%@/%@/%@.png",[self dataPath],setting._NowSN,[dateFormat stringFromDate:selected]] atomically:YES];
[dateFormat release];
}