1 /*****************************************************************************
6 * Created by Martin Kahr on 11.03.06 under a MIT-style license.
7 * Copyright (c) 2006 martinkahr.com. All rights reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 *****************************************************************************
29 * Note that changes made by any members or contributors of the VideoLAN team
30 * (i.e. changes that were exclusively checked in to one of VideoLAN's source code
31 * repositories) are licensed under the GNU General Public License version 2,
32 * or (at your option) any later version.
33 * Thus, the following statements apply to our changes:
35 * Copyright (C) 2006-2009 VLC authors and VideoLAN
36 * Authors: Eric Petit <titer@m0k.org>
37 * Felix Kühne <fkuehne at videolan dot org>
39 * This program is free software; you can redistribute it and/or modify
40 * it under the terms of the GNU General Public License as published by
41 * the Free Software Foundation; either version 2 of the License, or
42 * (at your option) any later version.
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU General Public License for more details.
49 * You should have received a copy of the GNU General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
52 *****************************************************************************/
54 #import "AppleRemote.h"
56 /* this was added by the VideoLAN team to ensure Leopard-compatibility and is VLC-only */
58 #import "CompatibilityFixes.h"
60 const char* AppleRemoteDeviceName = "AppleIRController";
61 const int REMOTE_SWITCH_COOKIE=19;
62 const NSTimeInterval DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE=0.35;
63 const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
65 @implementation AppleRemote
67 @synthesize openInExclusiveMode = _openInExclusiveMode, clickCountEnabledButtons = _clickCountEnabledButtons, maximumClickCountTimeDifference = _maxClickTimeDifference, processesBacklog=_processesBacklog, simulatesPlusMinusHold = _simulatePlusMinusHold;
69 #pragma public interface
71 static AppleRemote *_o_sharedInstance = nil;
73 + (AppleRemote *)sharedInstance
75 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
80 if (_o_sharedInstance) {
83 _o_sharedInstance = [super init];
84 _openInExclusiveMode = YES;
86 hidDeviceInterface = NULL;
87 NSMutableDictionary * mutableCookieToButtonMapping = [[NSMutableDictionary alloc] init];
89 [mutableCookieToButtonMapping setObject:@(kRemoteButtonVolume_Plus) forKey:@"33_31_30_21_20_2_"];
90 [mutableCookieToButtonMapping setObject:@(kRemoteButtonVolume_Minus) forKey:@"33_32_30_21_20_2_"];
91 [mutableCookieToButtonMapping setObject:@(kRemoteButtonMenu) forKey:@"33_22_21_20_2_33_22_21_20_2_"];
92 [mutableCookieToButtonMapping setObject:@(kRemoteButtonPlay) forKey:@"33_23_21_20_2_33_23_21_20_2_"];
93 [mutableCookieToButtonMapping setObject:@(kRemoteButtonRight) forKey:@"33_24_21_20_2_33_24_21_20_2_"];
94 [mutableCookieToButtonMapping setObject:@(kRemoteButtonLeft) forKey:@"33_25_21_20_2_33_25_21_20_2_"];
95 [mutableCookieToButtonMapping setObject:@(kRemoteButtonRight_Hold) forKey:@"33_21_20_14_12_2_"];
96 [mutableCookieToButtonMapping setObject:@(kRemoteButtonLeft_Hold) forKey:@"33_21_20_13_12_2_"];
97 [mutableCookieToButtonMapping setObject:@(kRemoteButtonMenu_Hold) forKey:@"33_21_20_2_33_21_20_2_"];
98 [mutableCookieToButtonMapping setObject:@(kRemoteButtonPlay_Sleep) forKey:@"37_33_21_20_2_37_33_21_20_2_"];
99 [mutableCookieToButtonMapping setObject:@(k2009RemoteButtonPlay) forKey:@"33_21_20_8_2_33_21_20_8_2_"];
100 [mutableCookieToButtonMapping setObject:@(k2009RemoteButtonFullscreen) forKey:@"33_21_20_3_2_33_21_20_3_2_"];
102 if( OSX_SNOW_LEOPARD )
103 /* 10.6.2+ Snow Leopard cookies */
104 [mutableCookieToButtonMapping setObject:@(kRemoteControl_Switched) forKey:@"19_"];
107 [mutableCookieToButtonMapping setObject:@(kRemoteControl_Switched) forKey:@"42_33_23_21_20_2_33_23_21_20_2_"];
109 _cookieToButtonMapping = [[NSDictionary alloc] initWithDictionary: mutableCookieToButtonMapping];
110 [mutableCookieToButtonMapping release];
113 _simulatePlusMinusHold = YES;
114 _maxClickTimeDifference = DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE;
117 return _o_sharedInstance;
121 [self stopListening:self];
122 [_cookieToButtonMapping release];
130 - (BOOL) remoteAvailable {
131 io_object_t hidDevice = [self findAppleRemoteDevice];
132 if (hidDevice != 0) {
133 IOObjectRelease(hidDevice);
140 - (BOOL) listeningToRemote {
141 return (hidDeviceInterface != NULL && _allCookies != NULL && queue != NULL);
144 - (void) setListeningToRemote: (BOOL) value {
146 [self stopListening:self];
148 [self startListening:self];
152 /* Delegates are not retained!
153 * http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_4.html
154 * Delegating objects do not (and should not) retain their delegates.
155 * However, clients of delegating objects (applications, usually) are responsible for ensuring that their delegates are around
156 * to receive delegation messages. To do this, they may have to retain the delegate. */
157 - (void) setDelegate: (id) _delegate {
158 if (_delegate && [_delegate respondsToSelector:@selector(appleRemoteButton:pressedDown:clickCount:)]==NO) return;
160 delegate = _delegate;
166 - (BOOL) clickCountingEnabled {
167 return self.clickCountEnabledButtons != 0;
169 - (void) setClickCountingEnabled: (BOOL) value {
171 [self setClickCountEnabledButtons: kRemoteButtonVolume_Plus | kRemoteButtonVolume_Minus | kRemoteButtonPlay | kRemoteButtonLeft | kRemoteButtonRight | kRemoteButtonMenu | k2009RemoteButtonPlay | k2009RemoteButtonFullscreen];
173 [self setClickCountEnabledButtons: 0];
177 - (BOOL) listeningOnAppActivate {
178 id appDelegate = [NSApp delegate];
179 return (appDelegate!=nil && [appDelegate isKindOfClass: [AppleRemoteApplicationDelegate class]]);
181 - (void) setListeningOnAppActivate: (BOOL) value {
183 if ([self listeningOnAppActivate]) return;
184 AppleRemoteApplicationDelegate* appDelegate = [[AppleRemoteApplicationDelegate alloc] initWithApplicationDelegate: [NSApp delegate]];
185 /* NSApp does not retain its delegate therefore we keep retain count on 1 */
186 [NSApp setDelegate: appDelegate];
188 if ([self listeningOnAppActivate]==NO) return;
189 AppleRemoteApplicationDelegate* appDelegate = (AppleRemoteApplicationDelegate*)[NSApp delegate];
190 id previousAppDelegate = [appDelegate applicationDelegate];
191 [NSApp setDelegate: previousAppDelegate];
192 [appDelegate release];
196 - (IBAction) startListening: (id) sender {
197 if ([self listeningToRemote]) return;
199 io_object_t hidDevice = [self findAppleRemoteDevice];
200 if (hidDevice == 0) return;
202 if ([self createInterfaceForDevice:hidDevice] == NULL) {
206 if ([self initializeCookies]==NO) {
210 if ([self openDevice]==NO) {
216 [self stopListening:self];
219 IOObjectRelease(hidDevice);
222 - (IBAction) stopListening: (id) sender {
223 if (eventSource != NULL) {
224 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
225 CFRelease(eventSource);
229 (*queue)->stop(queue);
232 (*queue)->dispose(queue);
234 //release the queue we allocated
235 (*queue)->Release(queue);
240 if (_allCookies != nil) {
241 [_allCookies autorelease];
245 if (hidDeviceInterface != NULL) {
247 (*hidDeviceInterface)->close(hidDeviceInterface);
249 //release the interface
250 (*hidDeviceInterface)->Release(hidDeviceInterface);
252 hidDeviceInterface = NULL;
258 @implementation AppleRemote (Singleton)
260 static AppleRemote* sharedInstance=nil;
262 + (AppleRemote*) sharedRemote {
263 @synchronized(self) {
264 if (sharedInstance == nil) {
265 sharedInstance = [[self alloc] init];
268 return sharedInstance;
270 + (id)allocWithZone:(NSZone *)zone {
271 @synchronized(self) {
272 if (sharedInstance == nil) {
273 return [super allocWithZone:zone];
276 return sharedInstance;
278 - (id)copyWithZone:(NSZone *)zone {
284 - (NSUInteger)retainCount {
285 return UINT_MAX; //denotes an object that cannot be released
296 @implementation AppleRemote (PrivateMethods)
298 - (void) setRemoteId: (int) value {
302 - (IOHIDQueueInterface**) queue {
306 - (IOHIDDeviceInterface**) hidDeviceInterface {
307 return hidDeviceInterface;
310 - (NSDictionary*) cookieToButtonMapping {
311 return _cookieToButtonMapping;
314 - (NSString*) validCookieSubstring: (NSString*) cookieString {
315 if (cookieString == nil || [cookieString length] == 0) return nil;
316 NSEnumerator* keyEnum = [[self cookieToButtonMapping] keyEnumerator];
318 while((key = [keyEnum nextObject])) {
319 NSRange range = [cookieString rangeOfString:key];
320 if (range.location == 0) return key;
325 - (void) sendSimulatedPlusMinusEvent: (id) time {
326 BOOL startSimulateHold = NO;
327 AppleRemoteEventIdentifier event = lastPlusMinusEvent;
328 @synchronized(self) {
329 startSimulateHold = (lastPlusMinusEvent>0 && lastPlusMinusEventTime == [time doubleValue]);
331 if (startSimulateHold) {
332 lastEventSimulatedHold = YES;
333 event = (event==kRemoteButtonVolume_Plus) ? kRemoteButtonVolume_Plus_Hold : kRemoteButtonVolume_Minus_Hold;
334 [delegate appleRemoteButton:event pressedDown: YES clickCount: 1];
338 - (void) sendRemoteButtonEvent: (AppleRemoteEventIdentifier) event pressedDown: (BOOL) pressedDown {
340 if (self.simulatesPlusMinusHold) {
341 if (event == kRemoteButtonVolume_Plus || event == kRemoteButtonVolume_Minus) {
343 lastPlusMinusEvent = event;
344 lastPlusMinusEventTime = [NSDate timeIntervalSinceReferenceDate];
345 [self performSelector:@selector(sendSimulatedPlusMinusEvent:)
346 withObject:@(lastPlusMinusEventTime)
347 afterDelay:HOLD_RECOGNITION_TIME_INTERVAL];
350 if (lastEventSimulatedHold) {
351 event = (event==kRemoteButtonVolume_Plus) ? kRemoteButtonVolume_Plus_Hold : kRemoteButtonVolume_Minus_Hold;
352 lastPlusMinusEvent = 0;
353 lastEventSimulatedHold = NO;
355 @synchronized(self) {
356 lastPlusMinusEvent = 0;
364 if ((self.clickCountEnabledButtons & event) == event) {
365 if (pressedDown==NO && (event == kRemoteButtonVolume_Minus || event == kRemoteButtonVolume_Plus)) {
366 return; // this one is triggered automatically by the handler
368 NSNumber* eventNumber;
369 NSNumber* timeNumber;
370 @synchronized(self) {
371 lastClickCountEventTime = [NSDate timeIntervalSinceReferenceDate];
372 if (lastClickCountEvent == event) {
373 eventClickCount = eventClickCount + 1;
377 lastClickCountEvent = event;
378 timeNumber = @(lastClickCountEventTime);
379 eventNumber= @(event);
381 [self performSelector: @selector(executeClickCountEvent:)
382 withObject: @[eventNumber, timeNumber]
383 afterDelay: _maxClickTimeDifference];
385 [delegate appleRemoteButton:event pressedDown: pressedDown clickCount:1];
390 - (void) executeClickCountEvent: (NSArray*) values {
391 AppleRemoteEventIdentifier event = [values[0] unsignedIntValue];
392 NSTimeInterval eventTimePoint = [values[1] doubleValue];
394 BOOL finishedClicking = NO;
395 int finalClickCount = eventClickCount;
397 @synchronized(self) {
398 finishedClicking = (event != lastClickCountEvent || eventTimePoint == lastClickCountEventTime);
399 if (finishedClicking) eventClickCount = 0;
402 if (finishedClicking) {
403 [delegate appleRemoteButton:event pressedDown: YES clickCount:finalClickCount];
404 if ([self simulatesPlusMinusHold]==NO && (event == kRemoteButtonVolume_Minus || event == kRemoteButtonVolume_Plus)) {
405 // trigger a button release event, too
406 [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow:0.1]];
407 [delegate appleRemoteButton:event pressedDown: NO clickCount:finalClickCount];
413 - (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues {
415 if (previousRemainingCookieString) {
416 cookieString = [previousRemainingCookieString stringByAppendingString: cookieString];
417 NSLog(@"New cookie string is %@", cookieString);
418 [previousRemainingCookieString release], previousRemainingCookieString=nil;
420 if (cookieString == nil || [cookieString length] == 0) return;
421 NSNumber* buttonId = [[self cookieToButtonMapping] objectForKey: cookieString];
422 if (buttonId != nil) {
423 [self sendRemoteButtonEvent: [buttonId intValue] pressedDown: (sumOfValues>0)];
425 // let's see if a number of events are stored in the cookie string. this does
426 // happen when the main thread is too busy to handle all incoming events in time.
427 NSString* subCookieString;
428 NSString* lastSubCookieString=nil;
429 while((subCookieString = [self validCookieSubstring: cookieString])) {
430 cookieString = [cookieString substringFromIndex: [subCookieString length]];
431 lastSubCookieString = subCookieString;
432 if (self.processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
434 if (self.processesBacklog == NO && lastSubCookieString != nil) {
435 // process the last event of the backlog and assume that the button is not pressed down any longer.
436 // The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be
437 // a button pressed down event while in reality the user has released it.
438 // NSLog(@"processing last event of backlog");
439 [self handleEventWithCookieString: lastSubCookieString sumOfValues:0];
441 if ([cookieString length] > 0) {
442 msg_Warn( VLCIntf, "Unknown AR button for cookiestring %s", [cookieString UTF8String]);
449 /* Callback method for the device queue
450 Will be called for any event of any type (cookie) to which we subscribe
452 static void QueueCallbackFunction(void* target, IOReturn result, void* refcon, void* sender) {
453 AppleRemote* remote = (AppleRemote*)target;
455 IOHIDEventStruct event;
456 AbsoluteTime zeroTime = {0,0};
457 NSMutableString* cookieString = [NSMutableString string];
458 SInt32 sumOfValues = 0;
459 while (result == kIOReturnSuccess)
461 result = (*[remote queue])->getNextEvent([remote queue], &event, zeroTime, 0);
462 if ( result != kIOReturnSuccess )
465 //printf("%d %d %d\n", event.elementCookie, event.value, event.longValue);
467 if (REMOTE_SWITCH_COOKIE == (int)event.elementCookie) {
468 [remote setRemoteId: event.value];
469 [remote handleEventWithCookieString: @"19_" sumOfValues: 0];
471 if (((int)event.elementCookie)!=5) {
472 sumOfValues+=event.value;
473 [cookieString appendString:[NSString stringWithFormat:@"%d_", event.elementCookie]];
478 [remote handleEventWithCookieString: cookieString sumOfValues: sumOfValues];
481 @implementation AppleRemote (IOKitMethods)
483 - (IOHIDDeviceInterface**) createInterfaceForDevice: (io_object_t) hidDevice {
485 IOCFPlugInInterface** plugInInterface = NULL;
486 HRESULT plugInResult = S_OK;
488 IOReturn ioReturnValue = kIOReturnSuccess;
490 hidDeviceInterface = NULL;
492 ioReturnValue = IOObjectGetClass(hidDevice, className);
494 if (ioReturnValue != kIOReturnSuccess) {
495 msg_Err( VLCIntf, "Failed to get IOKit class name.");
499 ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice,
500 kIOHIDDeviceUserClientTypeID,
501 kIOCFPlugInInterfaceID,
504 if (ioReturnValue == kIOReturnSuccess)
506 //Call a method of the intermediate plug-in to create the device interface
507 plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &hidDeviceInterface);
509 if (plugInResult != S_OK) {
510 msg_Err( VLCIntf, "Couldn't create HID class device interface");
513 if (plugInInterface) (*plugInInterface)->Release(plugInInterface);
515 return hidDeviceInterface;
518 - (io_object_t) findAppleRemoteDevice {
519 CFMutableDictionaryRef hidMatchDictionary = NULL;
520 IOReturn ioReturnValue = kIOReturnSuccess;
521 io_iterator_t hidObjectIterator = 0;
522 io_object_t hidDevice = 0;
524 // Set up a matching dictionary to search the I/O Registry by class
525 // name for all HID class devices
526 hidMatchDictionary = IOServiceMatching(AppleRemoteDeviceName);
528 // Now search I/O Registry for matching devices.
529 ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
531 if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
532 hidDevice = IOIteratorNext(hidObjectIterator);
535 // release the iterator
536 IOObjectRelease(hidObjectIterator);
541 - (BOOL) initializeCookies {
542 IOHIDDeviceInterface122** handle = (IOHIDDeviceInterface122**)hidDeviceInterface;
543 IOHIDElementCookie cookie;
547 NSArray* elements = nil;
548 NSDictionary* element;
551 if (!handle || !(*handle)) return NO;
553 /* Copy all elements, since we're grabbing most of the elements
554 * for this device anyway, and thus, it's faster to iterate them
555 * ourselves. When grabbing only one or two elements, a matching
556 * dictionary should be passed in here instead of NULL. */
557 success = (*handle)->copyMatchingElements(handle, NULL, (CFArrayRef*)&elements);
559 if (success == kIOReturnSuccess) {
561 [elements autorelease];
563 cookies = calloc(NUMBER_OF_APPLE_REMOTE_ACTIONS, sizeof(IOHIDElementCookie));
564 memset(cookies, 0, sizeof(IOHIDElementCookie) * NUMBER_OF_APPLE_REMOTE_ACTIONS);
566 NSMutableArray *mutableAllCookies = [[NSMutableArray alloc] init];
567 NSUInteger elementCount = [elements count];
568 for (NSUInteger i=0; i< elementCount; i++) {
569 element = elements[i];
572 object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementCookieKey) ];
573 if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
574 if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID()) continue;
575 cookie = (IOHIDElementCookie) [object longValue];
578 object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsageKey) ];
579 if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
580 usage = [object longValue];
583 object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsagePageKey) ];
584 if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
585 usagePage = [object longValue];
587 [mutableAllCookies addObject: @((int)cookie)];
589 _allCookies = [[NSArray alloc] initWithArray: mutableAllCookies];
590 [mutableAllCookies release];
598 - (BOOL) openDevice {
601 IOHIDOptionsType openMode = kIOHIDOptionsTypeNone;
602 if ([self openInExclusiveMode]) openMode = kIOHIDOptionsTypeSeizeDevice;
603 IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, openMode);
605 if (ioReturnValue == KERN_SUCCESS) {
606 queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface);
608 result = (*queue)->create(queue, 0, 12); //depth: maximum number of elements in queue before oldest elements in queue begin to be lost.
610 NSUInteger cookieCount = [_allCookies count];
611 for(NSUInteger i=0; i<cookieCount; i++) {
612 IOHIDElementCookie cookie = (IOHIDElementCookie)[_allCookies[i] intValue];
613 (*queue)->addElement(queue, cookie, 0);
616 // add callback for async events
617 ioReturnValue = (*queue)->createAsyncEventSource(queue, &eventSource);
618 if (ioReturnValue == KERN_SUCCESS) {
619 ioReturnValue = (*queue)->setEventCallout(queue,QueueCallbackFunction, self, NULL);
620 if (ioReturnValue == KERN_SUCCESS) {
621 CFRunLoopAddSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
622 //start data delivery to queue
623 (*queue)->start(queue);
626 msg_Err( VLCIntf, "Error when setting event callout");
629 msg_Err( VLCIntf, "Error when creating async event source");
632 msg_Err( VLCIntf, "Error when opening HUD device");
640 @implementation AppleRemoteApplicationDelegate
642 - (id) initWithApplicationDelegate: (id) delegate {
643 if((self = [super init]))
644 applicationDelegate = [delegate retain];
649 [applicationDelegate release];
653 - (id) applicationDelegate {
654 return applicationDelegate;
657 - (void)applicationWillBecomeActive:(NSNotification *)aNotification {
658 if ([applicationDelegate respondsToSelector: @selector(applicationWillBecomeActive:)]) {
659 [applicationDelegate applicationWillBecomeActive: aNotification];
662 - (void)applicationDidBecomeActive:(NSNotification *)aNotification {
663 [[AppleRemote sharedRemote] setListeningToRemote: YES];
665 if ([applicationDelegate respondsToSelector: @selector(applicationDidBecomeActive:)]) {
666 [applicationDelegate applicationDidBecomeActive: aNotification];
669 - (void)applicationWillResignActive:(NSNotification *)aNotification {
670 [[AppleRemote sharedRemote] setListeningToRemote: NO];
672 if ([applicationDelegate respondsToSelector: @selector(applicationWillResignActive:)]) {
673 [applicationDelegate applicationWillResignActive: aNotification];
676 - (void)applicationDidResignActive:(NSNotification *)aNotification {
677 if ([applicationDelegate respondsToSelector: @selector(applicationDidResignActive:)]) {
678 [applicationDelegate applicationDidResignActive: aNotification];
682 - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
683 NSMethodSignature* signature = [super methodSignatureForSelector: aSelector];
684 if (signature == nil && applicationDelegate != nil) {
685 signature = [applicationDelegate methodSignatureForSelector: aSelector];
690 - (void)forwardInvocation:(NSInvocation *)invocation {
691 SEL aSelector = [invocation selector];
693 if (applicationDelegate==nil || [applicationDelegate respondsToSelector:aSelector]==NO) {
694 [super forwardInvocation: invocation];
698 [invocation invokeWithTarget:applicationDelegate];