对于从文件目录(和共享文档与iTunes)读取文件使用此:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"FILE_NAME" stringByAppendingString:@".EXTENSION"]];
并在您的info.plist还设置了关键Application supports iTunes file sharing
为YES
对于阅读嵌入项目(没有iTunes的文件共享)和链接与文件系统的文件夹的文件中使用此:
#define EXAMPLES_PATH @"/examplesPics/"
- (NSString *) relativePathForExampleImage: (NSString *) fileName {
return [[EXAMPLES_PATH stringByAppendingString:self.folderName] stringByAppendingString:fileName];
}
- (NSString *) absolutePathForExampleImage: (NSString *) fileName {
return [[[NSBundle mainBundle] bundlePath] stringByAppendingString:[self relativePathForExampleImage:fileName]];
}
并将examplesPics文件夹添加到“Copy Bundle Resources”构建阶段。
如果没有linkded文件夹,只需在您的项目组合使用:
- (NSString *) absolutePathForExampleImage: (NSString *) fileName {
return [[[NSBundle mainBundle] bundlePath] stringByAppendingString:fileName];
}
非常感谢!它的工作完美! :) – An1Ba7
它应该是...'fromPath:file' – Mundi
@AnkurBarthakur如果我的解决方案工作,为什么你不接受它? –