javascript - iPhone/iOS - [NSBundle mainBundle] pathForResources 无法查看 Javascript 文件

标签 javascript iphone ios nsbundle nsdocumentdirectory

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

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

最佳答案

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

关于javascript - iPhone/iOS - [NSBundle mainBundle] pathForResources 无法查看 Javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9453929/

相关文章:

javascript - 如何仅使用带有 Node 的 http 来监听 GET 请求?无 express

iphone - 如何在AppStore上的应用程序描述中添加任何语言?对下载量影响巨大!

iphone - 如何获得认证玩家的高分表格排行榜(游戏中心)

android - HTML 格式在 android 上看起来不错,但在 iphone 上却不行

ios - 带有 float 单元格的 UITableView

javascript - AngularJS 链接函数的顺序不正确

javascript - 如何通过在模态窗口外单击来关闭模态?

javascript - 对来自第三方控件的事件使用react,更新状态

iphone - ios流mp3并录制声音

iphone - 为什么我在 iOS 上使用 tan() 函数会遇到这个问题?