IOS Intro - Write file

 

 

 

#import <sys/xattr.h>

+ (NSString *)getFullFilePathInDocuments:(NSString *)subFilePath fileName:(NSString *)fileName
{
NSString *filePath = [NSString stringWithFormat:@"%@/Documents%@", NSHomeDirectory(), subFilePath];
// NSLog(@"function:%s,getFilePath %@", __FUNCTION__,filePath);
NSFileManager* fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:filePath]) {
return [NSString stringWithFormat:@"%@/%@", filePath, fileName];
}
if ([fm createDirectoryAtPath:filePath
withIntermediateDirectories:YES
attributes:nil
error:nil])
{
u_int8_t b = 1;
setxattr([filePath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
return [NSString stringWithFormat:@"%@/%@", filePath, fileName];
}
return nil;
}

self.mFile = [MagicEntity getFullFilePathInDocuments:@"/test" fileName:@"yuv.bin"];

NSData *data = [[NSData alloc] initWithBytes:I420 length:w * h * 3 / 2];
bool r = [data writeToFile:self.mFile atomically:true];

posted on 2017-06-27 17:34  fanbird2008  阅读(180)  评论(0编辑  收藏  举报

导航