2

我已将一个 javascript 文件添加到我的应用程序资源包中,我需要将其移至文档目录,但是当我启动其复制路径时,它返回 null。

代码:

NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"jsFile" ofType:@"js"];
NSString *copyPath = [path stringByAppendingString:@"/jsFile.js"];  //path is the documents dir
NSLog(@"%@", jsPath); //Output of this is (null)

if ([[NSFileManager defaultManager] fileExistsAtPath:jsPath]) //returns false
[[NSFileManager defaultManager] copyItemAtPath:jsPath toPath:copyPath error:nil];

以前有没有人遇到过这种情况?

4

1 回答 1

3

检查您的 js 文件是否已编译,而不是被复制到包中。您需要查看当前目标的“构建阶段”...

于 2012-02-26T14:36:30.950 回答