//判断是否允许使用麦克风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; 
}


发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

iOS微信第三方登录实现详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。