阅读了很多关于如何防止 iPhone 在运行我的应用程序时进入睡眠状态的内容,我现在非常不高兴,因为没有任何效果。
here https://stackoverflow.com/questions/1058717/idletimerdisabled-not-working-since-iphone-3-0我读到了每 30 秒设置一个计时器的想法,将idleTimerDisabled 设置为 NO,然后设置为 YES,但我的 objC 还不是那么好。谁能告诉我如何(以及在哪里)?
thnx!
编辑:
这是我尝试过的代码:
- (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];
}
edit3:你真的不能改变不小心被否决的吗?对 stackoverflow 系统来说将是一个很好的 chnage 请求!
关于你的问题关于使用计时器:
以下是如何让计时器在 30 秒后响起(仅一次):
-(void)_jump
{
// add this function up the top. it's what will happen when the
// timer goes off:
NSLog(@"Your timer went off!!!");
}
...
// here's how to create the timer, which will go off in 30 seconds
[NSTimer scheduledTimerWithTimeInterval:30.0
target:self selector:@selector(_jump) userInfo:nil repeats:NO]
如果你想两个不同的计时器,先是30秒,然后是60秒,用同样的方法做两个。如果您需要有关计时器的更多帮助,请告诉我!
这再简单不过了。只需添加这一行:
application.idleTimerDisabled = YES;
在“application didFinishLaunchingWithOptions”例程中。
你会发现你的日常习惯应用程序委托.m 源代码文件。
一定要添加它BEFORE“返回是;”声明 - 一个常见的错误!所以,就像这样:
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// blah blah ...
application.idleTimerDisabled = YES;
return YES;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)