[英]iOS Objective-C Image file name/path different behavior betwewen simulator and device
I have an app in which the app bundle contains an image file (I mean that the file is dragged into XCode and appears in "Other Sources"), and I am using code like: 我有一个应用程序,其中该应用程序捆绑包包含一个图像文件(我的意思是将该文件拖到XCode中并显示在“其他来源”中),并且我正在使用类似以下的代码:
[[NSBundle mainBundle] pathForResource:@"Auto" ofType:@"jpg"]
to get a path to the image. 获取图像的路径。
I found that when running on a device (iPod Touch), the name is case-sensitive, so that if the file is "Auto" and I use "AUTO", the poath returned is "file://(null)". 我发现在设备(iPod Touch)上运行时,名称区分大小写,因此,如果文件为“ Auto”,而我使用“ AUTO”,则返回的内容为“ file://(null)”。 However on the simulator, if I use "AUTO", it works the same as if I use "Auto". 但是在模拟器上,如果我使用“ AUTO”,则其工作方式与我使用“ Auto”相同。
I am thinking that the fact that the simulator has such a clear difference in behavior from the device is a bug. 我认为模拟器与设备在行为上有如此明显的区别是一个错误。 Do the more experienced users out there think that it is, and that I should report it to Apple? 那里经验更丰富的用户是否认为是这样,我应该向苹果报告?
Thanks. 谢谢。
The iOS-Filesystem is case-sensitive, whereas the OSX-Filesystem the Simulator uses isn't. iOS文件系统区分大小写,而模拟器使用的OSX文件系统则不区分大小写。
You have to be very careful with this, I've shot myself in the foot with this more than once. 您对此必须非常小心,我已经不止一次地将自己打倒在脚上。
This has more to do with NS/CFBundle itself than it does with the underlying file-system: 这与NS / CFBundle本身的关系比与基础文件系统的关系更多:
Directly from Bundle Programming Guide: The Bundle Search Pattern : 直接来自Bundle编程指南:Bundle搜索模式 :
Important : The bundle interfaces consider case when searching for resource files in the bundle directory. 重要说明 :在捆绑目录中搜索资源文件时,捆绑接口会考虑大小写。 This case-sensitive search occurs even on file systems (such as HFS+) that are not case sensitive when it comes to file names. 甚至在文件名不区分大小写的文件系统(例如HFS +)上也会进行区分大小写的搜索。
You should always, always be assuming case-sensitivity. 您应该始终保持区分大小写。 Well, perhaps a better way to express that is to say, never assume Case-insensitive-while-case-preserving (which is what HFS+ is). 好吧,也许这是一种更好的表达方式,那就是永远不要假设不区分大小写而保留大小写(这就是HFS +的含义)。 In the not-so-distant future, case-sensitive HFS+ could become the default format for Mac OS X. (In general, it would be preferred over the current case-preserving HFS+, but if Apple were to switch it now, there would likely be hundreds of thousands of apps that would break because of developers who made assumptions they shouldn't have. The iPhone is a clear example of the preference for case-sensitive HFS+. With no legacy programs to worry about, the iPhone has always been case-sensitive). 在不久的将来,区分大小写的HFS +可能会成为Mac OS X的默认格式。(通常,它比当前保留大小写的HFS +更为可取,但是如果Apple现在进行切换,则可以iPhone就是区分大小写的HFS +的首选示例,iPhone显然是偏爱区分大小写的HFS +的明显例子。由于没有开发者担心,iPhone一直是区分大小写)。
You are editing your code and resource names right now, so take the time to assure they match. 您现在正在编辑代码和资源名称,因此请花一些时间确保它们匹配。
I am thinking that the fact that the simulator has such a clear difference in behavior from the device is a bug. 我认为模拟器与设备在行为上有如此明显的区别是一个错误。
In general, this does not necessarily indicate a bug. 通常,这不一定表示有错误。
Do the more experienced users out there think that it is, and that I should report it to Apple? 那里经验更丰富的用户是否认为是这样,我应该向苹果报告?
Yes. 是。 But the bug has nothing to do with the device at all. 但是该错误与设备完全无关。 Specifically, the bug is simply "Simulator file paths are not case-sensitive". 具体来说,该错误仅是“ Simulator文件路径不区分大小写”。 If you can reproduce this in a "sandbox" project, do so, and submit it along with your bug report. 如果可以在“沙盒”项目中重现此内容,请这样做,然后将其与错误报告一起提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.