iOS开发笔记:大小写敏感的iOS文件系统,而iOS模拟器竟然对大小写不敏感

一个程序在模拟器上运行正常,但在真机上运行就是出错,排除了下列多种可能性:

(1)用5.0的SDK开发,部署在4.3的真机系统上

(2)越狱的iPhone机器

(3)文件的汉字编码不正确

(4)ZIP文件包解压到iPhone机器里有问题

(5)苹果开发证书安装不正确

最后发现是该死的iOS文件系统竟然对大小写敏感!!!静下心来想想也是,MAC等系统都是从UNIX系统修改过来的,大小写早应该小心。从网上查了一下,在这篇文章里有清楚的描述,原话是这样的:

Case Sensitivity

It’s important to understand that the iOS file system is case sensitive. This means that your file and directory names must match exactly – README.txt and readme.txt would be considered different filenames.

This could be confusing for .NET developers who are more familiar with the Windows file system, which is case insensitive– “Files”, “FILES”, and “files” would all refer to the same directory.

So, although iOS devices are case sensitive and your code should be written with that in mind, the iOS Simulator is NOT case sensitive by default. This means if your filename casing differs between the file itself and the references to it in code, your code might still work in the simulator but that it would fail on a real device. This is one of the reasons why it’s important to deploy to an actual device early and often during iOS development.

大意就是iOS的文件系统是大小写敏感的,而在iOS模拟器里不敏感!从.NET过来的程序员们经常忽略这个问题(我就是这样),这也是要经常地、尽早地进行真机调试的一个主要原因。

另外得到的一个小经验就是要对NSError的错误信息进行检查。

NSError *error = nil;

NSString *str = [[NSString alloc] initWithContentsOfFile:path encoding:enc error:&error];

要检查一下error对象,或者检查一下str对象,尽早发现错误。

 

 

posted @ 2012-03-03 15:22  申龙斌的程序人生  阅读(3255)  评论(2编辑  收藏  举报