Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AVAudioRecorderDelegate的代表没有打电话_Ios_Objective C_Audio_Audio Recording - Fatal编程技术网

Ios AVAudioRecorderDelegate的代表没有打电话

Ios AVAudioRecorderDelegate的代表没有打电话,ios,objective-c,audio,audio-recording,Ios,Objective C,Audio,Audio Recording,实际上,我想录制音频并存储到文档中,我找到了文件路径,甚至附加了音频文件,但我想将实际音频附加到该路径中,它不起作用,我在didfish中这样编写代码 - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"Recording Area"; [btnRecord setBackgroundImage:[UIImage imageNamed:@"Reco

实际上,我想录制音频并存储到文档中,我找到了文件路径,甚至附加了音频文件,但我想将实际音频附加到该路径中,它不起作用,我在didfish中这样编写代码

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.navigationItem.title = @"Recording Area";
        [btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal];

        session = [AVAudioSession sharedInstance];
        [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

        audioRecorder.delegate = self;


        NSDate *today = [[NSDate alloc]init];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        [dateFormatter setDateFormat:@"hh:mm:ss"];

        NSString *currentTime = [dateFormatter stringFromDate:today];

        NSString *outputPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];

        outputPath = [outputPath stringByAppendingString:[NSString stringWithFormat:@"%@.m4a",currentTime]];

        NSMutableDictionary *recordDictionary = [[NSMutableDictionary alloc] init];

        [recordDictionary setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
        [recordDictionary setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
        [recordDictionary setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];


        audioRecorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:outputPath] settings:recordDictionary error:nil];

        audioRecorder.meteringEnabled = YES;
        [audioRecorder prepareToRecord];

    }

and For Recording Audio

    -(IBAction)onClickRecord:(id)sender
{

    if(player.playing)
    {
        [player stop];
    }


    if([[btnRecord backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"Record.png"]])
    {

        if (!audioRecorder.recording)

        {
            AVAudioSession *session = [AVAudioSession sharedInstance];
            [session setActive:YES error:nil];


            [audioRecorder record];
           [btnRecord setBackgroundImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateNormal];
        }



    }

    else if([[btnRecord backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"Pause.png"]])
    {
        [audioRecorder pause];

        [btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal];
    }




}
用于保存录制的音频

    -(IBAction)onClickSave:(id)sender
{
    [audioRecorder stop];
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setActive:NO error:nil];


}
最后是我的代码不起作用的委托,实际上我不能调用这个方法

 - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{


    [btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal];
    [arrayFiles addObject:recorder.url.absoluteString];
    NSLog(@"Array %@",arrayFiles);

}

因此,请指定我错在哪里。

在初始化
AVAudioRecorder

移动
audioRecorder.delegate=self在初始化之后

audioRecorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:outputPath] settings:recordDictionary error:nil];
audioRecorder.meteringEnabled = YES;
audioRecorder.delegate = self;

[audioRecorder prepareToRecord];

确保您的录音机具有
strong
reference在实际创建之前,您正在录音机上设置代理it@property(强,非原子)h文件中的AVAudioRecorder*录音机我创建了这个..谢谢@dan,他是第一个观察到这一点的人)