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对象,尽早发现错误。
----==== Email: slofslb (GTD) qq.com 请将(GTD)换成@ ====----
版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
作者:申龙斌的程序人生
---- 魔方、桥牌、象棋、游戏人生...
---- BASIC、C++、JAVA、C#、Haskell、Objective-C、Open Inventor、程序人生...
---- GTD伴我实现人生目标
---- 区块链生存训练
---- 用欧拉计划学Rust编程
---- 申龙斌的读书笔记(2011-2019)
----