我有一个运行 iOS 4.2.1 的 iPod touch 和一个运行 iOS 4.2 的模拟器。在模拟器中,我的代码运行得很好,但在设备上,它崩溃了。
有问题的代码是:
FILE *file = fopen([[@"niplot/" stringByAppendingString:text_field.text] fileSystemRepresentation], "w");
...
fprintf(file, "%s", [print_str UTF8String]); //crash occurs here, EXC BAD ACCESS
...
fclose(file);
这可能与文件或文件夹不存在有关吗?在这种情况下,模拟器为我创建了它们。我尝试在设备上手动创建文件和文件夹,但我不确定如何创建。另外,我还尝试了带或不带 .txt 扩展名的文件名。
最佳答案
这是some examples文件保存/加载/删除。
关于ios - fprintf 导致设备崩溃但模拟器不崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6508159/