解決這個問題的方法是首先創建UIApplication的子類,重寫setIdleTimerDisabled方法並使其無效。然後,添加一些您自己的方法,您可以從應用程序調用而不是使用普通的setter。通過這樣做,您將忽略所有可能會改變閒置定時器的消息,而不必使用自定義方法調用。這裏是你如何做到這一點:
編輯使用自定義的UIApplication子類的main.m文件:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* appClass = @"CustomUIApplicationSubclass";
NSString* delegateClass = nil;
int retVal = UIApplicationMain(argc, argv, appClass, delegateClass);
[pool release];
return retVal;
}
然後定義您的UIApplication子類:
@interface CustomUIApplicationSubclass : UIApplication {
}
- (void)disableIdleTimer;
- (void)enableIdleTimer;
@end
@implementation CustomUIApplicationSubclass
- (void)setIdleTimerDisabled:(BOOL)disabled
{
// do nothing! take that stupid ipod controller!
}
- (void)enableIdleTimer
{
[super setIdleTimerDisabled:NO];
}
- (void)disableIdleTimer
{
[super setIdleTimerDisabled:YES];
}
@end
這將迫使iPod的控制器使用自定義的UIApplication實例,當調用普通的setIdleTimerDisabled方法時,它不再執行任何操作。
我有同樣的問題。對我來說就像一個錯誤。 – NeilInglis 2010-04-12 22:42:13