ArunJTS
ArunJTS

Reputation: 264

iOS app out of memory handling

In an iOS application, I'm generating a 'voice recorder' functionality for continuous capturing of speech.

I use the following code for writing the speech in to a file.

//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];

My question is, in case the iOS device is going out of memory, how to handle the file writing situation?

Upvotes: 0

Views: 195

Answers (2)

ArunJTS
ArunJTS

Reputation: 264

@Infinity James, I obtained the free space using the method mentioned in following link. [link] (http://www.linkedin.com/groups/How-detect-total-available-free-72283.S.217861544)

Upvotes: 0

Infinity James
Infinity James

Reputation: 4735

There is a very similar question here:

iPhone: available disk space

I would check for the available disk space and appropriately determine whether to cancel the write and alert the user, or to just silently fail.

Upvotes: 1

Related Questions