In my app, I will be using a microphone to do some recording. From iOS7.0 onwards, the user is asked to check the permission to access the microphone before starting the audio.
I have a button 'Start Recording' in my app. Here it first checks the user's permission for recording.
Here's the code to do this:
if([[AVAudioSession sharedInstance] respondsToSelector:@selector(requestRecordPermission:)]) {
[[AVAudioSession sharedInstance] performSelector:@selector(requestRecordPermission:)
withObject:permissionBlock];
}
#ifndef __IPHONE_7_0
typedef void (^PermissionBlock)(BOOL granted);
#endif
PermissionBlock permissionBlock = ^(BOOL granted) {
NSLog(@"permissionBlock");
if (granted) {
[self doActualRecording];
} else {
// Warn no access to microphone
}
};
Now, I want to ask the user to authorize microphone use as the user starts the app. Then when the user selects Record button, it gives a popup message again.
A similar functionality happens with Location services. How can I do this for microphone access?