【问题标题】:Very strange behaviour of stringWithContentsOfFile: in XCodestringWithContentsOfFile: 在 XCode 中的非常奇怪的行为
【发布时间】:2012-05-26 16:07:27
【问题描述】:

我正在构建一个基于 HTML 的 iPad 应用程序,并且我正在从本地文件加载 HTML。在这些文件中,我需要 jQuery 库,所以我的项目中有 js 文件,我将使用 stringByEvaluatingJavaScriptFromString 或类似的东西加载它 - 现在这无关紧要。

当我使用以下代码时,NSLog 返回 null:

NSString *gameFileContents = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"jquery172" ofType:@"js"] encoding:NSASCIIStringEncoding error:nil];
NSLog(@"%@",gameFileContents);

当我只将文件的扩展名从 .js 更改为 .json 时,一切都很好。

NSString *gameFileContents = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"jquery172" ofType:@"json"] encoding:NSASCIIStringEncoding error:nil];
NSLog(@"%@",gameFileContents);

对文件的扩展名有任何限制吗?我可以这样使用该文件,但它似乎不正确 - 我喜欢一切都到位。

【问题讨论】:

    标签: javascript xcode ios5


    【解决方案1】:

    Xcode 总是显示类似警告 - 没有规则来处理架构 i386 的 sourcecode.javascript 类型的文件 '$(PROJECT_DIR)/--/.js' 这就是它不起作用的原因。

    结帐下面的线程进行详细讨论 - iPhone UIWebView local resources using Javascript and handling onorientationChange

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-13
      • 2011-03-01
      • 2020-12-02
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 2020-02-09
      • 1970-01-01
      相关资源
      最近更新 更多