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

本文探讨了一个程序在iOS模拟器上运行正常,但在真实设备上却出现错误的问题。最终发现原因是iOS文件系统的大小写敏感特性。文章还强调了在开发过程中进行真机测试的重要性,并建议检查NSError对象以及时发现潜在问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

(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对象,尽早发现错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

申龙斌

撸代码来深夜,来杯咖啡钱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值