1

I want to detect headset button click on iPhone, see Detect headset button click on iPhone SDK. I follow as the http://developer.apple.com/library/IOS/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.html, then I wrote code as below, but it cannot work!!

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
    if (receivedEvent.type == UIEventTypeRemoteControl) {
        NSLog(@"Remote Control Event");
        switch (receivedEvent.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                NSLog(@"UIEventSubtypeRemoteControlTogglePlayPause");
                break;
            default:
                break;
        }
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
    [super viewWillDisappear:animated];
}

My Problem is that I cannot catch remote control event. When play or pause button on headset clicked, console prints nothing! Who can help me? Thank you.

Community
  • 1
  • 1
Smeegol
  • 2,014
  • 4
  • 29
  • 44

1 Answers1

1

Is your Info.plist updated to indicate that you support audio?

From http://www.iphonedevsdk.com/forum/iphone-sdk-development/44433-there-way-respond-clicks-headphone-buttons.html

Add the new line, and select "Required Background Modes". In the "Item 0" that appears under/next to it, select "App plays audio".

Emil
  • 7,220
  • 17
  • 76
  • 135
ThomasW
  • 16,981
  • 4
  • 79
  • 106
  • @SmeegolXie you need to provide more information on what you tried and didn't try. – ThomasW Mar 21 '12 at 02:54
  • this app is not about playing audio, just wanna catch the headset's button click event. My colleague told me that play/pause event cannot be detected without playing audio. Is is right? Cann't I just catch play/pause event through headset without playing audio? Thank you. – Smeegol Mar 21 '12 at 03:14