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 {
// 耳机没有mic
return YES;
}
return NO;
}
|