我正在开发一个 iphone 应用程序,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