I was working on the voice record feature for one of my upcoming iPhone apps, but when I would try to start recording the app would crash. During the adventure of debugging I couldn't trace anything back to my code as far as memory leaks, uninitialized properties, missing delegate methods, etc. After about an hour I think I almost as many NSLog entries as I did code. The two biggest troubling aspects where:
- prepareToRecord was the method that was failing
- AVAudioRecorder initialization wasn't throwing any errors
I turned to
some sample code that I knew worked, but mine would still fail. At this point I knew it was going to be something little that I was overlooking. After reading through a few posts on
StackOverFlow I noticed a difference in my audio configuration settings that was being passed to:
initWithURL:settings:error: I have a separate class where I set the settings argument. The last two setting items are for:
AVLinearPCMIsBigEndianKey and
AVLinearPCMIsFloatKey. Their values need to be NSNumbers so I was using
[NSNumber numberWithBool:], but instead of passing in "YES" or "NO" I was passing in
TRUE and
FALSE, which is
INCORRECT. Just one of those oversights I forget about when switching from one language to another.
I am still not sure why my
NSError wasn't populated with some information. I don't know why the initializer didn't catch my syntax error either.
After I made my corrections, the recording worked
perfectly. Whew! Now I just need to write the playback portion.