I have the following problem in my iOS application.
My application allows a user to write some text and save it in a txt file, but this doesn’t work for a chinese user.
A chinese user is able to write chinese text on the device and the text appears correctly on the device but it is saved incorrectly on the text file. If the user load the saved file the text is loaded with incorrect characters.
To save file I use the following instructions in Objective C:
Most probably it will work fine with NSUTF8StringEncoding.
Sometimes it depends when you use WEB APIs the documentation for the WEB APIs probably says what encoding is used. When you fetching Web API data you should use whatever encoding the service is using. You can discuss with API developer for the same or you can try out with the more different languages.
In most cases NSUTF8StringEncoding will work fine.
do you remind this post, I was not able to read chinese character and you suggested me to use NSUTF8StringEncoding. I answered you that now works well but today I found that with NSUTF8StringEncoding I can’t read large file. If I try to read a file of about 9MB I have the following error:
Error Domain=NSCocoaErrorDomain Code=261 “The file “KingBaseLite.txt” couldn’t be opened using text encoding Unicode (UTF-8).” UserInfo={NSFilePath=/Users/giordanovicoli/Library/Developer/CoreSimulator/Devices/8BEEEF25-620C-4B29-BD4A-E31B3C169E05/data/Containers/Data/Application/D0394678-DCCC-4D3E-8F9F-3B8685C80625/Documents/KingBaseLite.txt, NSStringEncoding=4}
If I change the Encoding with NSISOLatin1StringEncoding the file is read correctly but I am not able to save chinese text. Is there a solution that satisfies all requests?
Using NSISOLatin2StringEncoding I can read large file but I can’t save chinese text:
Error Domain=NSCocoaErrorDomain Code=517 “The file couldn’t be saved using the specified text encoding.” UserInfo={NSFilePath=/Users/giordanovicoli/Library/Developer/CoreSimulator/Devices/C5E8E0D3-0E45-45E2-9931-6AB4A7988B3F/data/Containers/Data/Application/ACAB9507-7AF4-4C0C-B118-D0BAC0CEA37F/Documents/pippo.pgn, NSStringEncoding=9}