I am embedding the AQRecorder class from the Apple SpeakHere example in my project using ARC. To compile it, I needed to create a class (AQRecorderController) that manages the AQRecorder instance (equivalent to SpeakHereController in the example). AQRecorderController is connected through the tip of my main view controller and implemented as a property. The problem arises whether the property is strong or weak.
My problem is that shortly after loading the view controller, AQRecorderController is released, but only when testing on the device. this does not happen in the simulator. This happens for iPad and iPhone, iOS 5 and iOS 6. I need to keep this link for the entire life of my view controller for recording purposes (you cannot delete the recorder during recording and expect to receive a finished file).
Has anyone come across this or something similar? If the AQRecorderController property is strong, an attempt to use it raises an invalid access error, if it is weak, I just get zero and cannot be used.
Any help would be greatly appreciated.
formViewController.h:
AQRecorderController.h
formView.xib: 
Here is the stack trace after the AQRecorderController has been released:
2012-10-23 10:34:09.600 TestApp[510:907] ( 0 TestApp 0x000f32ab -[AQRecorderController dealloc] + 138 1 CoreFoundation 0x32247311 CFRelease + 100 2 CoreFoundation 0x3225195d <redacted> + 140 3 libobjc.A.dylib 0x31ad5489 <redacted> + 168 4 CoreFoundation 0x32249441 _CFAutoreleasePoolPop + 16 5 Foundation 0x37303a7f <redacted> + 466 6 CoreFoundation 0x322db5df <redacted> + 14 7 CoreFoundation 0x322db291 <redacted> + 272 8 CoreFoundation 0x322d9f01 <redacted> + 1232 9 CoreFoundation 0x3224cebd CFRunLoopRunSpecific + 356 10 CoreFoundation 0x3224cd49 CFRunLoopRunInMode + 104 11 GraphicsServices 0x32fb52eb GSEventRunModal + 74 12 UIKit 0x34e92301 UIApplicationMain + 1120 13 TestApp 0x00081a9d main + 48 14 TestApp 0x0005aa68 start + 40 )
This creates an instance of the recorder.
AQRecorderController.mm:
- (void)awakeFromNib { aqRecorder = new AQRecorder(); }
It uses a recorder. At this point, the AQRecorderController has been released and this code is never executed (this causes a crash because the AQRecorderController has been released).
-(bool)startRecording { if (aqRecorder->IsRunning()) { [self stopRecording]; } else
}
This is where the instance of AQRecorderController is created.
formViewController.mm:
//this is called in viewDidAppear -(void)initializeAQRecorder: (NSString*)soundFileName { aqRecorderController = [[AQRecorderController alloc] init]; NSLog(@"AQRecorderController is being initialized for file %@",soundFileName); NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; NSString *soundFilePath =[[NSString alloc] initWithFormat:@"%@",[documentsDir stringByAppendingPathComponent:soundFileName]]; [aqRecorderController setFileName:soundFilePath]; [aqRecorderController initializeRecordSettingsWithCompression:NO]; }