La respuesta de Can fue buena, pero creo que está desactualizada.
Ahora necesita subclase UIApplication.
código para main.m
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "MyUIApplication.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(
argc,
argv,
NSStringFromClass([MyUIApplication class]),
NSStringFromClass([AppDelegate class]));
}
}
Código de MyUIApplication.m
:
@implementation MyUIApplication
- (void)sendEvent:(UIEvent *)event {
if (event.type == UIEventTypeRemoteControl) {
// Check event.subtype to see if it's a single click, double click, etc.
} else {
// Not my problem.
[super sendEvent:event];
}
}
@end
Código de AppDelegate.m
:
interior de - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
llamada [application beginReceivingRemoteControlEvents];
Gracias Can. Encontré otra solución usando el método: "remoteControlReceivedWithEvent:". La solución se trata aquí: http://www.iphonedevsdk.com/forum/iphone-sdk-development/44433-there-way-respond-clicks-headphone-buttons.html – MCO
@Puede haber probado su solución y la El tipo de evento sendEvent UIEventTypeRemoteControl no se llama cuando presiono los botones de mis auriculares. ¿Hay alguna otra configuración que hayas hecho para que esto funcione? La subclase está funcionando ya que capto algunos otros eventos. –