Is there a way to detect the headset\'s play/pause button click?
I managed to detect the volume buttons clicks using:
AudioSessionAddPropertyListener
Can's answer was good, but I think it's outdated.
Now you need to subclass UIApplication.
code for main.m
#import
#import "AppDelegate.h"
#import "MyUIApplication.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(
argc,
argv,
NSStringFromClass([MyUIApplication class]),
NSStringFromClass([AppDelegate class]));
}
}
Code for 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
Code for AppDelegate.m
:
inside of - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
call [application beginReceivingRemoteControlEvents];