iOS应用程序内存处理不足

时间:2013-11-12 09:34:12

标签: ios file memory

在iOS应用程序中,我正在为连续捕获语音生成“录音机”功能。

我使用以下代码将语音写入文件。

//output speech
NSString *filePath = [root stringByAppendingPathComponent:@"output_speech.raw"];
if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
    [[NSData data] writeToFile:filePath atomically:YES];
}
NSData *myData = [NSData dataWithBytes:ptrOut length:DataByteSize];
NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:filePath];
[handle truncateFileAtOffset:[handle seekToEndOfFile]];
[handle writeData:myData];
[handle closeFile];

我的问题是,如果iOS设备内存不足,如何处理文件写入情况?

2 个答案:

答案 0 :(得分:1)

这里有一个非常相似的问题:

iPhone: available disk space

我会检查可用的磁盘空间,并适当地确定是取消写入并提醒用户,还是静默失败。

答案 1 :(得分:0)

@Infinity James,我使用以下链接中提到的方法获得了可用空间。 [link](http://www.linkedin.com/groups/How-detect-total-available-free-72283.S.217861544