phonegap, iphone and the big bad idleTimerDisabled

懵懂的女人 提交于 2019-12-04 13:36:58

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!