phonegap、iphone 和最大的坏处idleTimerDisabled
阅读了很多关于如何防止 iphone 在运行我的应用程序时进入睡眠状态的内容,我现在非常不高兴,因为没有任何效果。.
here 我读到了每 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];
}
edit3: 你真的不能意外地更改否决票吗?对 stackoverflow 系统来说将是一个很好的 chnage 请求!
reading a lot about how to prevent iphone goingto sleep while running my app I am very unhappy at the moment because nothing worked..
here I read about the idea to set up a timer for every 30 seconds to set the idleTimerDisabled to NO and then YES, but my objC isn't that good yet. could anybody tell me how (and where)?
thnx!
edit:
here is the code I tried:
- (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: after that I tried to start a loop with:
-(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: you really can't change accidentially downvotes? would be a nice chnage request to the stackoverflow system!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于您关于使用计时器的问题:
以下是如何让计时器在 30 秒内关闭(仅一次):
如果您想要两个不同的计时器,请说30秒,然后60秒,用同样的方法做两个即可。如果您需要有关计时器的更多帮助,请告诉我!
这再简单不过了。只需添加这一行:
在“application didFinishLaunchingWithOptions”例程中。
您将在 app delegate .m 源代码文件中找到该例程。
请务必将其添加到“return YES;”之前声明 - 一个常见的错误!所以,就像这样:
Regarding your question about using a timer:
Here is how you make a timer go off (just once) in 30 seconds from now:
If you want two different timers, after say 30 and then 60 seconds, just make two in the same way. Let me know if you need more help with timers!
It couldn't be easier. Just add this line:
Inside your "application didFinishLaunchingWithOptions" routine.
You will find that routine inside your app delegate .m source code file.
Be sure to add it BEFORE the "return YES;" statement - a common mistake! So, exactly like this:
只需设置 [UIApplication sharedApplication].idleTimerDisabled = YES;在
对我来说效果很好。但是,有一个警告。我注意到,每次我从 PhoneGap 应用程序调用相机实用程序来拍摄快照时,idleTimerDisable 都会在幕后设置为 NO。因此,在我上传图像后,我再次调用了以下代码行:
[UIApplication sharedApplication].idleTimerDisabled = YES;
另外,如果应用程序中有更多地方重新启用空闲计时器,我也不会感到惊讶。
Just setting [UIApplication sharedApplication].idleTimerDisabled = YES; in
works well for me. However, there is a caveat. I have noticed that every time I invoke camera utility from my phonegap app to take a snapshot, idleTimerDisable gets set to NO behind the scene. So right after i upload my image, I had call the following line of code again:
[UIApplication sharedApplication].idleTimerDisabled = YES;
Also, I would not be surprised if there are more places throughout the app idle timer gets reenabled.