Remote-control
Users can use external interfaces to control application music. The official recommendation is to receive remote-control events when the view is displayed.
-(Void) viewdidappear :( bool) animated <br/>{< br/> [Super viewdidappear: animated]; <br/> [[uiapplication sharedapplication] beginreceivingremotecontrolevents]; <br/> [self becomefirstresponder]; <br/>}
Then, when the view disappears, the remote-control event is canceled.
-(Void) viewwilldisappear :( bool) animated <br/>{< br/> [Super viewwilldisappear: animated]; <br/> [[uiapplication sharedapplication] endreceivingremotecontrolevents]; <br/> [self resignfirstresponder]; <br/>}
Another point is that the RESP receiving reomte-control must be first responder, so canbecamefirstresponder must be rewritten.
-(Bool) canbecomefirstresponder <br/>{< br/> return yes; <br/>}
Another simple method is to derive a uiwindow and rewrite its-(void) remotecontrolreceivedwithevent: (uievent *) receivedevent Method
-(Void) remotecontrolincluedwithevent: (uievent *) receivedevent {</P> <p> If (receivedevent. type = uieventtyperemotecontrol) {</P> <p> switch (receivedevent. subtype) {</P> <p> case uieventsubtyperemotecontroltoggleplaypause: <br/> [self playorstop: Nil]; <br/> break; </P> <p> case uieventsubtyperemotecontrolprevioustrack: <br/> [self previoustrack: Nil]; <br/> break; </P> <p> case uieventsubtyperemotecontrolnexttrack: <br/> [self nexttrack: Nil]; <br/> break; </P> <p> default: <br/> break; <br/>}< br/>}
Is it simpler ?!