To record audio on a real iOS device, remember to config audio session before a recording is started.
An audio session is the intermediary between an app and iOS used to configure the app’s audio behaviour. If category "AVAudioSessionCategoryPlayAndRecord" is set, it defines iOS audio behaviour to allow audio input (recording) and output (playback).
To record audio in iLBC format, noted to remove AVSampleRateKey key in settings and change file extension to "ilbc" is necessary.
let audioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) } catch let error as NSError { print(error.description) } let recordSettings = [AVSampleRateKey : NSNumber(float: Float(44100.0)), AVFormatIDKey : NSNumber(int: Int32(kAudioFormatMPEG4AAC)), AVNumberOfChannelsKey : NSNumber(int: 1), AVEncoderAudioQualityKey : NSNumber(int: Int32(AVAudioQuality.Max.rawValue))] do{ try recorder = AVAudioRecorder(URL: getFileURL(), settings: recordSettings) recorder.delegate = self recorder.prepareToRecord() } catch let error as NSError { error.description }