iOS 헤드폰 작업
10439 단어 ios
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) { // } else { dispatch_async(dispatch_get_main_queue(), ^{ [[[UIAlertView alloc] initWithTitle:@" " message:@" “ - - ” xx " delegate:nil cancelButtonTitle:@" " otherButtonTitles:nil] show]; }); } }]; }
아이폰 감지 이어폰 삽입/뽑기
핸드폰의 현재 사용 여부를 판단하는 것은 내장된 마이크이다(이 방법으로 삽입된 이어폰에 마이크가 있는지 판단할 수 있다)
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; }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다. Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.