iOS headset operation

Source: Internet
Author: User

iOS after 7 add the microphone permission to the application, the code is as follows:

123456789         
Avaudiosession*Avsession=[AvaudiosessionSharedinstance];If([AvsessionRespondstoselector:@selector(Requestrecordpermission:)]){ [AvsessionRequestrecordpermission:^(BOOLAvailable){ If(Available){ Have microphone permissions }Else{ dispatch_async (dispatch_get_main_queue (), ^{ [[[ Uialertview alloc] initwithtitle:@ "unable to record" message:@ "please allow XX access to your microphone in the" settings-privacy-Microphone "option" delegate: Nil cancelbuttontitle:@ "OK" otherbuttontitles: nil show]; ); } }]; }             /span>                

iphone detection headset Insert/unplug

Determine if the phone is currently using a built-in microphone (this method can be used to determine if the headset has a microphone)

123456789Each of the Ten + All in all.       
-(BOOL)Iscurrentusingbuildinmicrophone{ Nserror*Error=Nil; BOOLResult=YES; Result=[[AvaudiosessionSharedinstance]Setcategory:AvaudiosessioncategoryplayandrecordError&Error]; If(!Result){ NSLog(@"%@",Error); ReturnYES; } Result=[[AvaudiosessionSharedinstance]SetActive:YESError&Error]; If(!Result){ NSLog(@ "SetActive failed"); ReturnYES; } CfdictionaryrefArds; UInt32Size=sizeof(Cfdictionaryref); OsstatusOs=Audiosessiongetproperty(Kaudiosessionproperty_audioroutedescription,&Size,&Ards); If(Os==Kaudiosessionnoerror&&Ards&&Cfdictionarygetvalue(Ards,Kaudiosession_audioroutekey_inputs)){ Nsarray*Inputs=(__bridgeNsarray*)Cfdictionarygetvalue(Ards,Kaudiosession_audioroutekey_inputs); If(Inputs&&Inputs.Count>0){ For(Nsdictionary*DicInchInputs){ NSString*Type=Dic[(__bridgeNSString*)Kaudiosession_audioroutekey_type]; If([TypeIsequaltostring: (__bridge nsstring *) kaudiosessioninputroute_builtinmic) { return yes; } } } } else { //headset without Mic  return yes; } return no;                /span>                

iOS Headset action

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.