I am using the new iOS7 developer SDK and now the app request from the user his permission to record from mic when the App try to record in the first time.
My App will record after a countdown,so the user can't see this request.
I use this code to check the requestRecordPermission
:
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
if (granted) {
// Microphone enabled code
}
else {
// Microphone disabled code
}
}];
But how can i trigger the request by myself before i start to record ?
In the new iOS7 it's very simple try this:
if([[AVAudioSession sharedInstance] respondsToSelector:@selector(requestRecordPermission)])
{
[[AVAudioSession sharedInstance] requestRecordPermission];
}
Here is final code snippet that does work for me. It support both Xcode 4 and 5, and works for iOS5+.
#ifndef __IPHONE_7_0
typedef void (^PermissionBlock)(BOOL granted);
#endif
PermissionBlock permissionBlock = ^(BOOL granted) {
if (granted)
{
[self doActualRecording];
}
else
{
// Warn no access to microphone
}
};
// iOS7+
if([[AVAudioSession sharedInstance] respondsToSelector:@selector(requestRecordPermission:)])
{
[[AVAudioSession sharedInstance] performSelector:@selector(requestRecordPermission:)
withObject:permissionBlock];
}
else
{
[self doActualRecording];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With