iphone – iOS将文件从主包复制到文档目录
发布时间:2020-12-14 19:51:56 所属栏目:百科 来源:网络整理
导读:我正在尝试将我添加到名为“includes”的文件夹的文件复制到名为“includes”的文档目录上的文件夹.我得到resContents nil值.为什么?谢谢 - (void)copyResources{ NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComp
我正在尝试将我添加到名为“includes”的文件夹的文件复制到名为“includes”的文档目录上的文件夹.我得到resContents nil值.为什么?谢谢
- (void)copyResources{ NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"includes"]; NSString *destPath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"includes"]; NSArray* resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:sourcePath error:NULL]; for (NSString* obj in resContents){ NSError* error; if (![[NSFileManager defaultManager] copyItemAtPath:[sourcePath stringByAppendingPathComponent:obj] toPath:[destPath stringByAppendingPathComponent:obj] error:&error]) NSLog(@"Error: %@",error);; } } 解决方法
您应该将Xcode项目的include文件夹添加为文件夹引用而不是组.
组只是为了保持组织而不是提供文件夹结构,因此当复制到设备时,所有文件最终都在同一级别. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |