iOS Developer Library

Developer

AVFoundation Framework Reference AVAudioRecorderDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

AVAudioRecorderDelegate

Inheritance


Not Applicable

Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

Availability


Available in iOS 3.0 and later.

The delegate of an AVAudioRecorder object must adopt the AVAudioRecorderDelegate protocol. All of the methods in this protocol are optional. They allow a delegate to respond to audio interruptions and audio decoding errors, and to the completion of a recording.

  • Called by the system when a recording is stopped or has finished due to reaching its time limit.

    Declaration

    Swift

    optional func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder!, successfully flag: Bool)

    Objective-C

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

    Parameters

    recorder

    The audio recorder that has finished recording.

    flag

    YEStrue on successful completion of recording; NOfalse if recording stopped because of an audio encoding error.

    Discussion

    This method is not called by the system if the audio recorder stopped due to an interruption.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 3.0 and later.

  • Called when an audio recorder encounters an encoding error during recording.

    Declaration

    Swift

    optional func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder!, error error: NSError!)

    Objective-C

    - (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error

    Parameters

    recorder

    The audio recorder that encountered the encoding error.

    error

    Returns, by-reference, a description of the error, if an error occurs.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 3.0 and later.

  • Called when the audio session is interrupted during a recording, such as by an incoming phone call.

    Deprecation Statement

    Register for the AVAudioSession class’s notification AVAudioSessionInterruptionNotification instead.

    Declaration

    Swift

    optional func audioRecorderBeginInterruption(_ recorder: AVAudioRecorder!)

    Objective-C

    - (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder

    Parameters

    recorder

    The audio recorder whose recording was interrupted.

    Discussion

    Upon interruption, your application’s audio session is deactivated and the audio recorder pauses. You cannot use the audio recorder again until you receive a notification that the interruption has ended.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 2.2 and later.

    Deprecated in iOS 8.0.

  • Called after your audio session interruption ends, with options indicating the state of the audio session.

    Deprecation Statement

    Register for the AVAudioSession class’s notification AVAudioSessionInterruptionNotification instead.

    Declaration

    Swift

    optional func audioRecorderEndInterruption(_ recorder: AVAudioRecorder!, withOptions flags: Int)

    Objective-C

    - (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder withOptions:(NSUInteger)flags

    Parameters

    recorder

    The paused audio recorder whose interruption has ended.

    flags

    Options indicating the state of the audio session when this method is called. Options are described in AVAudioSessionInterruptionOptions

    Discussion

    For an audio recorder’s delegate to receive this message, the audio recorder must have been recording when the interruption started. When an interruption ends, such as by a user ignoring an incoming phone call, the audio session for your application is automatically reactivated; at that point you can again interact with the audio recorder. To resume recording, call the record method.

    If this delegate method receives the AVAudioSessionInterruptionOptionShouldResume constant in its flags parameter, the audio session is immediately ready to be used.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 6.0 and later.

    Deprecated in iOS 8.0.

  • Called after your audio session interruption ends.

    Deprecation Statement

    Register for the AVAudioSession class’s notification AVAudioSessionInterruptionNotification instead.

    Declaration

    Objective-C

    - (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder

    Parameters

    recorder

    The paused audio recorder whose interruption has ended.

    Discussion

    If you implement the preferred audioRecorderEndInterruption:withFlags: method, it will be called instead of this one.

    For an audio recorder’s delegate to receive this message, the audio recorder must have been recording when the interruption started. When an interruption ends, such as by a user ignoring an incoming phone call, the audio session for your application is automatically reactivated; at that point you can again interact with the audio recorder. To resume recording, call the record method.

    Import Statement

    Objective-C

    @import AVFoundation;

    Availability

    Available in iOS 2.2 and later.

    Deprecated in iOS 6.0.

  • Called after your audio session interruption ends, with flags indicating the state of the audio session.

    Deprecation Statement

    Register for the AVAudioSession class’s notification AVAudioSessionInterruptionNotification instead.

    Declaration

    Objective-C

    - (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder withFlags:(NSUInteger)flags

    Parameters

    recorder

    The paused audio recorder whose interruption has ended.

    flags

    Flags indicating the state of the audio session when this method is called. Flags are described in Interruption Flags.

    Discussion

    For an audio recorder’s delegate to receive this message, the audio recorder must have been recording when the interruption started. When an interruption ends, such as by a user ignoring an incoming phone call, the audio session for your application is automatically reactivated; at that point you can again interact with the audio recorder. To resume recording, call the record method.

    If this delegate method receives the AVAudioSessionInterruptionFlags_ShouldResume constant in its flags parameter, the audio session is immediately ready to be used.

    If you implement this method, the system does not call the audioRecorderEndInterruption: method.

    Import Statement

    Objective-C

    @import AVFoundation;

    Availability

    Available in iOS 4.0 and later.

    Deprecated in iOS 6.0.