phonegap,iphone和大坏idleTimerDisabled [英] phonegap, iphone and the big bad idleTimerDisabled

查看:406
本文介绍了phonegap,iphone和大坏idleTimerDisabled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读很多关于如何防止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 
{
// 。当
//定时器关闭时会发生什么:
NSLog(@你的计时器关闭了!
}


/ **
*这是在应用程序启动后主要启动,视图和设置在这里设置。
* /
- (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:偶然downvote?将是一个很好的chnage请求stackoverflow系统!

解决方案

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



以下是如何让计时器在30秒后关闭(只有一次):

   - void)_jump 
{
//在顶部添加此函数。当
//定时器关闭时会发生什么:
NSLog(@你的计时器关闭了!
}
...
//这里是如何创建定时器,将在30秒后关闭
[NSTimer scheduledTimerWithTimeInterval:30.0
target:self selector: @selector(_jump)userInfo:nil重复:NO]

后,说30秒然后60秒,只是使两个相同的方式。让我知道如果您需要更多的计时器帮助!






这不容易。只需添加以下行:

  application.idleTimerDisabled = YES; 

在应用程序didFinishLaunchingWithOptions例程中。



您会在应用程式委托 .m源代码文件中找到该例程。



请务必添加 BEFORE return YES;语句 - 一个常见的错误!所以,完全像这样:

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

application.idleTimerDisabled = YES;
return YES;
}


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!

解决方案

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;
    }

这篇关于phonegap,iphone和大坏idleTimerDisabled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆