-(BOOL) canbecomefirstresponder{
NSLog (@ "_____%s_____", __function__);
return YES;
}
Received remote event
-(void) Remotecontrolreceivedwithevent: (uievent *) event{
NSLog (@ "event tyipe:::%d subtype:::%d", Event.type,event.subtype);
type==2 subtype== Click Pause Key: 103, double-click Pause Key 104
if (Event.type = = Uieventtyperemotecontrol) {
Switch (event.subtype) {
Case uieventsubtyperemotecontrolplay:{
NSLog (@ "Play---------");
}break;
Case uieventsubtyperemotecontrolpause:{
NSLog (@ "Pause---------");
}break;
Case uieventsubtyperemotecontrolstop:{
NSLog (@ "Stop---------");
}break;
Case uieventsubtyperemotecontroltoggleplaypause:{
Click Pause Key: 103
NSLog (@ "Click Pause key: 103");
}break;
Case uieventsubtyperemotecontrolnexttrack:{
Double-click Pause key: 104
NSLog (@ "Double-click Pause key: 104");
}break;
Case uieventsubtyperemotecontrolprevioustrack:{
NSLog (@ "Three hit pause key: 105");
}break;
Case uieventsubtyperemotecontrolbeginseekingforward:{
NSLog (@ "Click, then press not put: 108");
}break;
Case uieventsubtyperemotecontrolendseekingforward:{
NSLog (@ "Click, then press not to put, loosen when: 109");
}break;
Default
Break
}
}
}
Add the above code to get the headset line control of each click event, tick the taxi before the version of a headset grab a single function, is so realized
====================================================================================================
Capture Headphone Plug event in iOS development
void Audioroutechangelistenercallback (
void *inuserdata,
Audiosessionpropertyid InID,
UInt32 Indatasize,
const void *indata)
{
UInt32 propertysize = sizeof (CFSTRINGREF);
Audiosessioninitialize (NULL, NULL, NULL, NULL);
Cfstringref state = nil;
Audiosessiongetproperty (Kaudiosessionproperty_audioroute
, &propertysize,&state);
NSLog (@ "%@", (NSString *) state);//return @ "headphone" or @ "Speaker" and "."
}
-(void) Viewdidload {
[Super Viewdidload];
Audiosessioninitialize (NULL, NULL, NULL, NULL);
Osstatus status = Audiosessionaddpropertylistener (
Kaudiosessionproperty_audioroutechange,
Audioroutechangelistenercallback,self);
if (status = = 0) {//ok}
}
====================================================================================================
First Import System class library
#import <AVFoundation/AVFoundation.h>
Monitor Headphone Events
[[Avaudiosessionsharedinstance] setdelegate:self];
Use this code instead to allow the app sound to continue to play when the ' screen ' is locked.
[[Avaudiosessionsharedinstance] setCategory:AVAudioSessionCategoryPlaybackerror:nil];
Registers the audio route Change listener callback function
Audiosessionaddpropertylistener (Kaudiosessionproperty_audioroutechange,audioroutechangelistenercallback, self);
Write this code where you need to listen.
I personally recommend to put
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOption
Because it's the big picture, where you can respond to it.
For example
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Self.window = [[[Uiwindowalloc] initwithframe:[[uiscreenmainscreen]bounds]]autorelease];
Landing VC
Loginviewcontroller *LOGINVC = [[Loginviewcontrolleralloc]init];
Uinavigationcontroller *NAVNV = [[UINAVIGATIONCONTROLLERALLOC]INITWITHROOTVIEWCONTROLLER:LOGINVC];
[Navnvsetnavigationbarhidden:yes];
[LOGINVC release];
Monitor Headphone Events
[[Avaudiosessionsharedinstance] setdelegate:self];
Use this code instead to allow the app sound to continue to play when the ' screen ' is locked.
[[Avaudiosessionsharedinstance] setCategory:AVAudioSessionCategoryPlaybackerror:nil];
Registers the audio route change listener