【发布时间】:2023-03-03 23:40:01
【问题描述】:
我的应用中有一堆目录和文件,例如images/misc/mainmenu_background.。我在“iPad Simulator 3.2”中运行以下代码:
NSString *images = [[NSBundle mainBundle] pathForResource:@"images" ofType:nil];
NSString *images_misc = [[NSBundle mainBundle] pathForResource:@"images/misc" ofType:nil];
NSString *images_misc_file = [[NSBundle mainBundle] pathForResource:@"images/misc/mainmenu_background.png" ofType:nil];
在此调用之后,images 包含路径 /Users/wic/Library/Application Support/iPhone Simulator/3.2/Applications/8F67150B-71E6-4735-8CC6-38B3CE6D3568/Foo.app/images。
但是images_misc 和images_misc_file 是nil。仔细检查我的文件系统以检查文件是否存在:
$ ls -l "/Users/wic/Library/Application Support/iPhone Simulator/3.2/Applications/8F67150B-71E6-4735-8CC6-38B3CE6D3568/Foo.app/images/misc/mainmenu_background.png"
-rw-rw-rw- 1 wic staff 30307 16 Feb 21:09 /Users/wic/Library/Application Support/iPhone Simulator/3.2/Applications/8F67150B-71E6-4735-8CC6-38B3CE6D3568/Foo.app/images/misc/mainmenu_background.png
显然文件在那里。
如果我切换到“iPad Simulator 4.0”或任何其他模拟器版本,一切都会按预期工作。
我的设置是否有问题,或者 iPad 3.2 中 NSBundle 的这种行为是否正确?不幸的是,我没有实际的物理 iPad 来测试它。
【问题讨论】:
标签: xcode ios-simulator nsbundle