前言:
我们Xcode项目工程里面有一个文件,以model-o.scnassets.zip为例,想复制到沙盒文件中。具体操作如下:
![](https://img.haomeiwen.com/i6545546/3fe5751cef840dd3.png)
// Resource文件夹下的文件
NSString * docPath = [[NSBundle mainBundle] pathForResource:@"model-o.scnassets" ofType:@".zip"];
// 沙盒路径
NSString *appLib = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] ;
// 执行操作
BOOLfilesPresent = [selfcopyMissingFile:docPathtoPath:appLib];
if(filesPresent) { NSLog(@"迁移OK"); }else{ NSLog(@"迁移NO"); [selfsetDirBaseSetting]; }
// 把Resource文件夹下的文件拷贝到沙盒
- (BOOL)copyMissingFile:(NSString*)sourcePath toPath:(NSString*)toPath{
BOOL retVal = YES; // If the file already exists, we'll return success…
NSString * finalLocation = [toPath stringByAppendingPathComponent:[sourcePath lastPathComponent]];
if (![[NSFileManager defaultManager] fileExistsAtPath:finalLocation])
{
retVal = [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:finalLocation error:NULL];
}
returnretVal;
}
完整代码(上面代码已经贴出):
![](https://img.haomeiwen.com/i6545546/9a03c4eb8d36ba64.png)
网友评论