0

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

    }
}
4

1 に答える 1

0

iOS6で初めて録音を開始するように指示するとすぐにオーディオ録音が終了するという問題がありました(iOS5ではうまく機能しました)。問題は、AVAudioRecorderのデリゲートを設定していたのですが、iOS6ではAVAudioSessionのデリゲートが非推奨になり、デリゲートを削除するとアプリが再び機能するようになりました。

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioSession_ClassReference/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/AVAudioSession/delegate

編集: @Flinkが尋ねたように。AVAudioRecorderを使用するオーディオを録音するためのラッパークラス(NSObjectのみを拡張)があります。コードの関連部分は以下のとおりです。

...
NSError *error = nil;
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
//the relevant part of code is this "if"
if(SYSTEM_VERSION_LESS_THAN(@"6") && delegate){
  audioRecorder.delegate = self.delegate;
}

BOOL ok = [audioRecorder prepareToRecord];

if (ok){
  if(duration){
    ok = [audioRecorder recordForDuration:duration];
  }
  else {
    ok = [audioRecorder record];
  }

  if(!ok) {
    LogError(...);
  }else {
    LogInfo(@"recording");
  }             
}else {
  LogError(...);    
}
...
于 2012-12-13T15:46:53.847 に答える