I'm using the Avaudiorecorder frame to do the recording.
This recording is different from the Speakhere on the official website, the biggest difference is that this must be recorded to complete to process the file, and the Speakhere example is able to achieve edge recording side of the effect of uploading.
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h> Introduction Framework, which is the basic feature of the use of recording functions
First of all, the default Avaudiorecorder recording format is. CAF, and most of the players do not support this format, the following paragraph is the format can make the recording format wav
Nsdictionary *recordsetting = [[Nsdictionary alloc] Initwithobjectsandkeys:
[NSNumber Numberwithfloat:44100.0],avsampleratekey,//sampling rate
[NSNumber Numberwithint:kaudioformatlinearpcm],avformatidkey,
[NSNumber numberwithint:16],avlinearpcmbitdepthkey,//sampling digits default 16
[NSNumber Numberwithint:2], number of avnumberofchannelskey,//channels
[NSNumber numberwithbool:no],avlinearpcmisbigendiankey,//big or small end is the memory organization way
[NSNumber numberwithbool:no],avlinearpcmisfloatkey,nil];//sampling signal is an integer or a floating-point number
Nsurl *recordedtmpfile = [Nsurl fileurlwithpath:[nstemporarydirectory () stringbyappendingpathcomponent: [NSString stringWithFormat: @ "%.0f.%@", [nsdate timeintervalsincereferencedate] * 1000.0, @ "WAV"]]]; Settings for file names
Setup the recorder to use this file and a record to it.
Avaudiorecorder *recorder = [[Avaudiorecorder alloc] Initwithurl:recordedtmpfile settings:recordsetting error:& ERROR];
[Recorder Preparetorecord];
[Recorder record];
The following code should be set when the current. m file is loaded
Avaudiosession * audiosession = [avaudiosession sharedinstance];
[Audiosession Setcategory:avaudiosessioncategoryplayandrecord Error: &error]; Set the audio category, which means that when the application starts, stop the other audio in the background
[Audiosession setactive:yes Error: &error];//setting current application audio active