http://blog.csdn.net/silencetq/article/details/8447400
I'm using the Avaudiorecorder framework to do the recording.
This recording is somewhat different from the Speakhere on the official website, the biggest difference is that this must be recorded to finish processing the file, while the Speakhere example is a way to achieve the effect of side recording side uploads.
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
Introducing the framework, which is the basic equipment for using the recording function
First of all, the default Avaudiorecorder format after recording is. CAF, and most of the players are not supported in this format, the following paragraph is a format that allows the recording format to be WAV
Nsdictionary *recordsetting = [[nsdictionary alloc] initwithobjectsandkeys:
[nsnumber numberwithfloat: 44100.0],avsampleratekey,//Sample rate
[nsnumber numberwithint: kaudioformatlinearpcm],avformatidkey,
[nsnumber numberwithint: +],avlinearpcmbitdepthkey,//sample number of digits default
[nsnumber Numberwithint: 2], number of avnumberofchannelskey,//channels
[nsnumber numberwithbool:NO],avlinearpcmisbigendiankey,//big or small end is the way memory is organized
[nsnumber numberwithbool:NO],Avlinearpcmisfloatkey,nil];//whether the sampled 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 record to it.
Avaudiorecorder *recorder = [[ avaudiorecorder alloc] initwithurl: recordedtmpfile settings : Recordsettingerror: &error];
[Recorder Preparetorecord];
[Recorder record];
The following code should be the current. m file load time set
Avaudiosession * audiosession = [avaudiosession sharedinstance];
[Audiosession setcategory: Avaudiosessioncategoryplayandrecord error: &error];//set audio category, This means that when the app starts, the background other audio is stopped
[Audiosession setActive:YES Error: &error];//Set current app audio activity
About recording under iOS