How do you record an audio in a view and getting the saved audio file after popping out in the parent view?
I am using embedded navigation controller in storyboard.
I have this code in my child view.
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
tempFilePath = [NSURL fileURLWithPath:[docsDir stringByAppendingPathComponent:[NSString stringWithFormat: @"record.%@", @"caf"]]];
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:tempFilePath settings:recordSetting error:nil];
[audioRecorder setDelegate:self];
[audioRecorder prepareToRecord];
[audioRecorder record];
Now, how am I gonna get that in my parent controller?
If you have one view controller recording audio, that view controller should save the audio before it gets dismissed.
And you should save it to a consistent place (e.g. a cache directory, a documents directory, whatever). And if you give it a predictable filename, you can have your parent view controller easily locate it to load it up again when needed.
Alternatively, you could get a handle to your parent view controller from the navigation controller and pass along either the path to the written out audio data (or a URL), or the raw audio
NSDataobject itself. It all depends on how you’ve implemented your code.