zoukankan      html  css  js  c++  java
  • iOS 设置录音权限

    1.问题描述:在首次进入控制器就弹出是否允许开启麦克风的权限提示,如果选择不允许,可在下次调用时提示用户去“设置”页面进行再次开启;

    2.代码

    + (BOOL)checkPermission{
        
    //    AVAudioSessionRecordPermission permission = [[AVAudioSession sharedInstance] recordPermission];
    //    return permission == AVAudioSessionRecordPermissionGranted;
        __block BOOL bCanRecord = YES;
        if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 7.0) {
            AVAuthorizationStatus videoAuthStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
             if (videoAuthStatus == AVAuthorizationStatusNotDetermined) {// 未询问用户是否授权
                 AVAudioSession *audioSession = [AVAudioSession sharedInstance];
                 if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
                     [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
                         if (granted) {
                             bCanRecord = YES;
                         } else {
                             bCanRecord = NO;
                         }
                     }];
                 }
             } else if(videoAuthStatus == AVAuthorizationStatusRestricted || videoAuthStatus == AVAuthorizationStatusDenied) {
                // 未授权
                [self showSetAlertView];
            } else{
                // 已授权
                NSLog(@"已授权");
            }
        }
        return bCanRecord;
    }
    
    //提示用户进行麦克风使用授权
    + (void)showSetAlertView {
        
        [LGAlert alertWithTitle:@"麦克风权限未开启" message:@"麦克风权限未开启,请进入系统【设置】>【隐私】>【麦克风】中打开开关,开启麦克风功能" cancelTitle:@"取消" cancelBlock:^{
        } confirmTitle:@"去设置" confirmBlock:^{
            //跳入当前App设置界面
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        }];
    };

    3.参考的主要网址:https://www.jianshu.com/p/e952ef3e33bc

  • 相关阅读:
    tree
    gridview XML
    http://jingyan.baidu.com/article/22a299b513f3db9e18376a5e.html
    tree btn
    sss rar jar
    ComponentOne Studio
    http://wpf_sl.cnblogs.com/ WPF/Silverlight深蓝团队
    ddddd
    [牛客每日一题] (前缀和+线性 DP) NC15553 数学考试
    [停更一周,我干了什么] [C++/QT] 一个基于avl树,trie树,哈希散列表的英汉词典
  • 原文地址:https://www.cnblogs.com/wusang/p/9114964.html
Copyright © 2011-2022 走看看