phonegap、iphone 和最大的坏处idleTimerDisabled

发布于 2024-11-03 22:44:29 字数 1658 浏览 5 评论 0原文

阅读了很多关于如何防止 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷爱 2024-11-10 22:44:29

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

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

您将在 app delegate .m 源代码文件中找到该例程。

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

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

    application.idleTimerDisabled = YES;
    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:

-(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]

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:

application.idleTimerDisabled = YES;

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:

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

    application.idleTimerDisabled = YES;
    return YES;
    }
溺渁∝ 2024-11-10 22:44:29

只需设置 [UIApplication sharedApplication].idleTimerDisabled = YES;在

  • (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

对我来说效果很好。但是,有一个警告。我注意到,每次我从 PhoneGap 应用程序调用相机实用程序来拍摄快照时,idleTimerDisable 都会在幕后设置为 NO。因此,在我上传图像后,我再次调用了以下代码行:

[UIApplication sharedApplication].idleTimerDisabled = YES;

另外,如果应用程序中有更多地方重新启用空闲计时器,我也不会感到惊讶。

Just setting [UIApplication sharedApplication].idleTimerDisabled = YES; in

  • (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文