美文网首页
iOS把Resource文件夹下的文件拷贝到沙盒

iOS把Resource文件夹下的文件拷贝到沙盒

作者: 晴天ccc | 来源:发表于2019-02-12 16:08 被阅读12次

前言:

我们Xcode项目工程里面有一个文件,以model-o.scnassets.zip为例,想复制到沙盒文件中。具体操作如下:

 // 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;

}

完整代码(上面代码已经贴出):

相关文章

网友评论

      本文标题:iOS把Resource文件夹下的文件拷贝到沙盒

      本文链接:https://www.haomeiwen.com/subject/pwskeqtx.html