サーバーからファイルをダウンロードし、UTF8Encoded
それをアプリのキャッシュフォルダーに保存し、そのコンテンツを単にNSString* var
. デバイスでは機能しますが、シミュレーターでは機能しません。コードは次のとおりです。
NSLog(@"File loaded into path: %@\n", localPath);
NSError* error;
NSString* tmpString = [NSString stringWithContentsOfFile:localPath encoding:NSUTF8StringEncoding error:&error];
NSLog(@"Error: %@", error);
//Prints the length in the console to check if the file has been correctly copied in the string
NSLog(@"tmpString length:%u", [tmpString length]);
シミュレーターでは、コードのこの部分が出力されます。
File loaded into path: /Users/username/Library/Application Support/iPhone Simulator/5.1/Applications/4FCF8FC6-4F1B-4FE5-92F6-A99EC8888E47/Library/Caches/utf8encodedFile.txt
しかし、" stringWithContentsOfFile:
" メソッドを呼び出すとクラッシュし、エラーは表示されません。
実際のデバイスではすべて正常に動作し、次のように出力されます。
File loaded into path: /var/mobile/Applications/1EE8AEEB-D036-4ADE-AE12-836BA1F16BCB/Library/Caches/utf8encodedFile.txt
2012-06-30 19:19:24.743 appName[685:707]
Error: (null)
2012-06-30 19:19:24.745 appName[685:707] tmpString length:1423