在我为 iOS 6 更新应用程序后,AVAudioRecorder
无法在设备上运行,并且在[soundRecorder prepareToRecord]
.
更新。:audioRecorderDidFinishRecording:successfully:
委托方法在之后立即触发[soundRecorder record];
有没有人找到一些修复?
- (IBAction)recordSound {
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.audioPlayer stop];
appDelegate.audioPlayer = nil;
[self stopPlaying];
if (soundRecorder.recording) {
[soundRecorder stop];
soundRecorder = nil;
[timer invalidate];
timer = nil;
NSError *error;
[[AVAudioSession sharedInstance] setActive: NO error: &error];
NSLog([error localizedDescription]);
}else{
NSManagedObject *oldSound = _sight.sound;
if (oldSound != nil) {
[__managedObjectContext deleteObject:oldSound];
}
[self saveContext];
if (!soundRecorder)
{
NSError *errorAudioSession;
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayAndRecord
error: &errorAudioSession];
NSLog([errorAudioSession description]);
NSDictionary *recordSettings =
@{AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVNumberOfChannelsKey: @1,
AVEncoderAudioQualityKey: @(AVAudioQualityMedium)};
NSError *error;
AVAudioRecorder *newRecorder =
[[AVAudioRecorder alloc] initWithURL: soundFileURL
settings: recordSettings
error: &error];
NSLog([error description]);
soundRecorder = newRecorder;
soundRecorder.delegate = self;
}
[soundRecorder stop];
[soundRecorder prepareToRecord];
[soundRecorder record];
timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(updateRecordStatus) userInfo:nil repeats:YES];
}
}