iOS中判断麦克风权限和应用中跳转至设置中当前应用处设置权限

判断权限是否有权限:

- (void)AuthorityToJudge:(id)sender
{
    [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
        if (granted) {
            // 用户同意开启麦克风权限
            NSLog(@"用户第一次允许了打开麦克风权限");
            //进行麦克风的操作
            [self RECMicBtnClicked];
        } else {
            // 用户不同意开启麦克风权限
            NSLog(@"用户第一次没有允许打开麦克风权限");
            //弹窗,提示用户跳转到设置页面设置权限
            [self PermissionToRequest];
        }
    }];
}

- (void)PermissionToRequest
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"此功能需要您开启麦克风权限,请前往设置中开启" preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"下次开启" style:UIAlertActionStyleDefault handler:nil]];
    [alert addAction:[UIAlertAction actionWithTitle:@"立即开启" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        
        if([[UIApplication sharedApplication] canOpenURL:url]) {

            NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
            
            [[UIApplication sharedApplication] openURL:url];
        }
    }]];
    [self presentViewController:alert animated:YES completion:nil];
}

 

转载于:https://my.oschina.net/u/2555813/blog/758005

你可能感兴趣的:(iOS中判断麦克风权限和应用中跳转至设置中当前应用处设置权限)