【问题标题】:iPhone / iOS - [NSBundle mainBundle] pathForResources not able to see Javascript filesiPhone / iOS - [NSBundle mainBundle] pathForResources 无法查看 Javascript 文件
【发布时间】:2012-03-16 06:30:46
【问题描述】:

我已将一个 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];

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

【问题讨论】:

    标签: javascript iphone ios nsbundle nsdocumentdirectory


    【解决方案1】:

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

    【讨论】:

    • 是的,我刚刚在 Stack 上的另一个问题中也找到了这个解决方案,但我之前没有注意到它,因为它没有被勾选为正确答案。无论如何,你是对的。
    • 很高兴听到您找到了解决方案!
    猜你喜欢
    • 1970-01-01
    • 2016-08-28
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多