IOS headset operation, ios headset

Source: Internet
Author: User

IOS headset operation, ios headset

The code for applying for microphone permissions added after iOS 7 is as follows:

123456789101112
AVAudioSession * avSession = [AVAudioSession sharedInstance]; if ([avSession respondsToSelector: @ selector (listener :)]) {[avSession requestRecordPermission: ^ (BOOL available) {if (available) {// microphone permission} else {dispatch_async (dispatch_get_main_queue (), ^ {[[[UIAlertView alloc] initWithTitle: @ "unable to record" message: @ "Please allow xx to access your microphone in the" Settings-privacy-microphone "option" delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil] show] ;}}}] ;}

Iphone detection headset insertion/removal

Determine whether the phone is currently using a built-in microphone (you can use this method to determine whether the inserted headset has a microphone)

123456789101112131415161718192021222324252627282930313233
-(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, Rules) {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 is0000tostring :( _ bridge NSString *) kAudioSessionInputRoute_BuiltInMic]) {return YES ;}}} else {// NO mic return YES For the headset;} return NO ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.