阅读了很多关于如何在运行我的应用程序时防止 iphone 进入睡眠状态的信息,我目前非常不高兴,因为没有任何效果..
在这里,我读到了每隔 30 秒设置一个计时器以将 idleTimerDisabled 设置为 NO 然后是 YES 的想法,但是我的 objC 还不是那么好。谁能告诉我如何(以及在哪里)?
谢谢!
编辑:这是我尝试过的代码:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[ super applicationDidFinishLaunching:application ];
//application.idleTimerDisabled = NO;
//application.idleTimerDisabled = YES;
//[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[UIApplication sharedApplication].idleTimerDisabled = NO;
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
edit2:之后我尝试使用以下方法开始循环:
-(void)_timerLoop
{
// add this function up the top. it's what will happen when the
// timer goes off:
NSLog(@"Your timer went off!!!");
}
/**
* This is main kick off after the app inits, the views and Settings are setup here.
*/
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[ super applicationDidFinishLaunching:application ];
//application.idleTimerDisabled = NO;
//application.idleTimerDisabled = YES;
//[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
//[UIApplication sharedApplication].idleTimerDisabled = NO;
//[UIApplication sharedApplication].idleTimerDisabled = YES;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(_timerLoop) userInfo:nil repeats:YES];
}
编辑3:你真的不能意外地改变投票吗?将是对 stackoverflow 系统的一个很好的更改请求!