[UIApplication sharedApplication].idleTimerDisabled=YES;
//当然一定要慎用,记着退出程序时把自动休眠功能开启
UIApplication sharedApplication].idleTimerDisabled=NO;
phonegap程序在Classes文件夹下的MainViewController.m中进行相关设置
#pragma UIWebDelegate implementation
- (void) webViewDidFinishLoad:(UIWebView*) theWebView
{
// only valid if ___PROJECTNAME__-Info.plist specifies a protocol to handle
if (self.invokeString)
{
// this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
}
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
[UIApplication sharedApplication].idleTimerDisabled = YES;//这里是相关代码
return [super webViewDidFinishLoad:theWebView];
}