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對象,盡早發現錯誤。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM