缶の答えは良かったのですが、時代遅れだと思います。
次に、UIApplicationをサブクラス化する必要があります。
のコード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]));
}
}
のコード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
のコードAppDelegate.m:
の中に- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
電話[application beginReceivingRemoteControlEvents];