模拟器和设备之间访问资源的差异?
问题描述:
捆绑资源可以在iPhone模拟器与设备(在我的情况下,iPad)上访问的方式有一些区别吗?我能够访问前者的文件,但不能访问后者。模拟器和设备之间访问资源的差异?
NSString *filePath = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] bundlePath], @"/AppResources/html/pages/quickHelp.html"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
// fileExists == YES in the debugger on both the simulator and the device
NSString *path = [NSString stringWithFormat:@"AppResources/html/pages/%@", contentsFileName];
NSString *pathForURL = [[NSBundle mainBundle] pathForResource:path ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:pathForURL isDirectory:NO];
的代码在模拟器上述工作正常,但在装置pathForResource:路径返回nil,所以最后一行抛出一个“零字符串参数”异常。
我失去了一些东西明显?
编辑:当然,在上面的@“quickHelp”正在通过contentsFileName var。
edit2如果它有什么不同,在我的构建设置中,“Base SDK”设置为“iPhone Device 4.0”,“iPhone OS Deployment Target”设置为“iPhone OS 3.1.3”。任何其他可能有影响的设置?
答
[忽略]
我看到了 '/' 在你的*文件路径,但不存在对*路径(AppResources前)
[/忽略]
[编辑]
[[一个NSBundle mainBundle] pathForResource:@ “快捷帮助” ofType:@ “html” 的inDirectory:@ “AppResources/HTML /页”]]
pathForRes补充说,不是吗?它在模拟器中,至少... 我不得不将它添加到* filePath中,以便我可以手动创建整个路径。 – Tony 2010-06-07 17:52:36
因为你正在寻找一个名为quickHelp.html的文件,你不应该只是把... pathForResource:@“quickHelp”ofType:@“html”]? (因为它会搜索你的应用程序路径) – KevinDTimm 2010-06-07 18:06:36
不,我不认为它会递归搜索子目录。无论如何,我的确尝试过,硬编码为pathForResource:@“quickHelp”ofType:@“html”,但是会导致代码在模拟器和设备中都失败。 – Tony 2010-06-07 18:16:38