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;
}
本文由用戶 GiseleGrang 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!