iOS耳机操作
iOS在7之后增加的麥克風(fēng)權(quán)限的申請(qǐng),代碼如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 | AVAudioSession *avSession = [AVAudioSession sharedInstance]; if ([avSession respondsToSelector:@selector(requestRecordPermission:)]) { [avSession requestRecordPermission:^(BOOL available) { if (available) { // 有麥克風(fēng)權(quán)限 } else { dispatch_async(dispatch_get_main_queue(), ^{ [[[UIAlertView alloc] initWithTitle:@"無(wú)法錄音" message:@"請(qǐng)?jiān)凇霸O(shè)置-隱私-麥克風(fēng)”選項(xiàng)中允許xx訪問(wèn)你的麥克風(fēng)" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil] show]; }); } }]; } |
iphone檢測(cè)耳機(jī)插入/拔出
判斷手機(jī)當(dāng)前是否使用的是內(nèi)置的麥克風(fēng)(可以用此方法判斷插入的耳機(jī)是否有麥克風(fēng))
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | - (BOOL)isCurrentUsingBuildInMicrophone { NSError *error = nil; BOOL result = YES; result = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error]; if (!result) { NSLog(@"%@", error); return YES; } result = [[AVAudioSession sharedInstance] setActive:YES error:&error]; if (!result) { NSLog(@"setActive failed"); return YES; } CFDictionaryRef ards; UInt32 size = sizeof(CFDictionaryRef); OSStatus os = AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &size, &ards); if (os == kAudioSessionNoError && ards && CFDictionaryGetValue(ards, kAudioSession_AudioRouteKey_Inputs)) { NSArray *inputs = (__bridge NSArray *)CFDictionaryGetValue(ards, kAudioSession_AudioRouteKey_Inputs); if (inputs && inputs.count > 0) { for (NSDictionary *dic in inputs) { NSString *type = dic[(__bridge NSString *)kAudioSession_AudioRouteKey_Type]; if ([type isEqualToString:(__bridge NSString *)kAudioSessionInputRoute_BuiltInMic]) { return YES; } } } } else { // 耳機(jī)沒(méi)有mic return YES; } return NO; } |
轉(zhuǎn)載于:https://www.cnblogs.com/lovewx/p/4155782.html
總結(jié)
- 上一篇: OC学习之面向对象三大特征
- 下一篇: IIS_FastCGI+php5.3+w