gpt4 book ai didi

iphone - phonegap、iphone 和最大的坏处idleTimerDisabled

转载 作者:行者123 更新时间:2023-12-03 19:42:05 25 4
gpt4 key购买 nike

阅读了很多关于如何防止 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 请求!

最佳答案

关于您有关使用计时器的问题:

以下是如何让计时器在 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”例程中。

您将在应用委托(delegate) .m 源代码文件中找到该例程。

请务必将其添加到“return YES;”之前声明 - 一个常见的错误!所以,就像这样:

-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// blah blah ...

application.idleTimerDisabled = YES;
return YES;
}

关于iphone - phonegap、iphone 和最大的坏处idleTimerDisabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5824072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com