七喜视频社区下载-win7智能abc

麦克风测试
2023年3月31日发(作者:ppt版式)

麦克风测试软件ios,iOS开发麦克风权限判断

在iOS开发中,我们经常要使⽤系统的各种权限!我们需要向系统进⾏申请,如果不申请会直接造成APP的闪退!

⾸先我们需要在⽂件中,加⼊以下代码

NSMicrophoneUsageDescription

请允许使⽤麦克风进⾏*****

在进⾏麦克风使⽤时候,我们需要对权限进⾏判断,我们是否有权限使⽤麦克风

引⼊头⽂件

#import

加⼊以下权限判断代码

AVAuthorizationStatusmicroPhoneStatus=[AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeAudio];

switch(microPhoneStatus){

caseAVAuthorizationStatusDenied:

caseAVAuthorizationStatusRestricted:

{

//被拒绝

[selfgoMicroPhoneSet];

}

break;

caseAVAuthorizationStatusNotDetermined:

{

//没弹窗

[selfrequestMicroPhoneAuth];

}

break;

caseAVAuthorizationStatusAuthorized:

{

//有授权

}

break;

default:

break;

}

如果还有进⾏申请,要进⾏权限申请

-(void)requestMicroPhoneAuth

{

[AVCaptureDevicerequestAccessForMediaType:AVMediaTypeAudiocompletionHandler:^(BOOLgranted){

}];

}

如果⽤户没有允许,可以进⾏弹窗提⽰,进⼊设置页⾯,让⽤户进⾏选择

-(void)goMicroPhoneSet

{

UIAlertController*alert=[UIAlertControlleralertControllerWithTitle:@"您还没有允许麦克风权限"message:@"去设置⼀下吧"

preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction*cancelAction=[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction

*_Nonnullaction){

}];

UIAlertAction*setAction=[UIAlertActionactionWithTitle:@"去设置"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*

_Nonnullaction){

dispatch_async(dispatch_get_main_queue(),^{

NSURL*url=[NSURLURLWithString:UIApplicationOpenSettingsURLString];

[ApplicationopenURL:urloptions:nilcompletionHandler:^(BOOLsuccess){

}];

});

}];

[alertaddAction:cancelAction];

[alertaddAction:setAction];

[selfpresentViewController:alertanimated:YEScompletion:nil];

}

更多推荐

麦克风测试