开发者

Differences in accessing resources between Simulator and Device?

Is there some difference between the way that bundle resources can be accessed on the iPhone simulator versus a device (in my case, an iPad)? I am able to access a file on the former, but not the latter.

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];

The code above works fine in the simulator, but on the device pathForResource:path returns nil, so the last line throws a 'nil string parameter' exception.

Am I missing something obvious?

edit: Of course, in the above @"quickHelp" is being passed in the contentsFileName var.

edit2: if it makes any difference, in my build settings "Base SDK" is set to "iPhone Device 4.0", and "i开发者_高级运维Phone OS Deployment Target" is set to "iPhone OS 3.1.3". Any other settings that might have an influence?


[ignore]
I notice a leading '/' on your *filePath but none exists on *path (before AppResources)
[/ignore]

[edit]
[[NSBundle mainBundle] pathForResource:@"quickHelp" ofType:@"html" inDirectory:@"AppResources/html/pages"]]
[/edit]


I believe the filesystem on the iPhone is case-sensitive. Check your cases with the actual files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜