How to check for microphone access at time of launch?

江枫思渺然 提交于 2019-12-04 04:25:26

Once a user has denied microphone access for your app, you cannot present them with the permissions dialog again. The saved settings are used. Instead you can prompt the user to go into their settings and make the change.

[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
    if (granted) {
        NSLog(@"granted");
    } else {
        NSLog(@"denied");

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Microphone Access Denied"
                                                            message:@"You must allow microphone access in Settings > Privacy > Microphone"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
       [alert show];
    }
}];
Opsimath

I had the same question. See this response to a related question including sample code for checking and handling permission status using AVAudioSession which you can customize to provide the user experience you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!