iOS判断手机是否开启麦克风详解手机开发

//判断是否允许使用麦克风7.0新增的方法requestRecordPermission 
-(BOOL)canRecord 
{ 
    __block BOOL bCanRecord = YES; 
    if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending) 
    { 
        AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
        if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) { 
            [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) { 
                if (granted) { 
                    bCanRecord = YES; 
                } 
                else { 
                    bCanRecord = NO; 
                    dispatch_async(dispatch_get_main_queue(), ^{ 
                        [[[UIAlertView alloc] initWithTitle:nil 
                                                    message:@"app需要访问您的麦克风。/n请启用麦克风-设置/隐私/麦克风" 
                                                   delegate:nil 
                                          cancelButtonTitle:@"关闭" 
                                          otherButtonTitles:nil] show]; 
                    }); 
                } 
            }]; 
        } 
    } 
     
    return bCanRecord; 
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/3334.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论