Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i request mic record permission from user

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. enter image description here

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 ?


2 Answers

In the new iOS7 it's very simple try this:

if([[AVAudioSession sharedInstance] respondsToSelector:@selector(requestRecordPermission)])
{
    [[AVAudioSession sharedInstance] requestRecordPermission];
}
like image 112
One Man Crew Avatar answered Sep 15 '25 12:09

One Man Crew


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];
    }
like image 39
Alex Bogomolov Avatar answered Sep 15 '25 13:09

Alex Bogomolov