iOS开发-麦克风授权的问题

开发过程中,遇到系统弹框麦克风授权,如果点了允许,或者不允许,一般再想让这个对话框出现,需要如下方法解决:

打开:系统设置-》通用-》还原-》还原位置与隐私,即可以实现让这个系统的对话框再次出现

有时候,还需要监测,第一次弹这个系统的 麦克风授权的对话框:需要使用如下函数,但是注意在iOS 8 及以上系统下使用

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

    
        AVAudioSessionRecordPermission permissionStatus = [[AVAudioSession sharedInstance] recordPermission];
        
        switch (permissionStatus) {
            case AVAudioSessionRecordPermissionUndetermined:{
                NSLog(@"第一次调用,是否允许麦克风弹框");
                [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
                    // CALL YOUR METHOD HERE - as this assumes being called only once from user interacting with permission alert!
                    if (granted) {
                        // Microphone enabled code
                    }
                    else {
                        // Microphone disabled code
                    }
                }];
                break;
            }
            case AVAudioSessionRecordPermissionDenied:
                // direct to settings...
                NSLog(@"已经拒绝麦克风弹框");

                break;
            case AVAudioSessionRecordPermissionGranted:
                NSLog(@"已经允许麦克风弹框");
                // mic access ok...
                break;
            default:
                // this should not happen.. maybe throw an exception.
                break;
        }
        if(permissionStatus == AVAudioSessionRecordPermissionUndetermined) return;
    }

 

posted @ 2016-04-10 20:40  elsonpeng  阅读(8744)  评论(0编辑  收藏  举报