[Han Jiang Gu Ye, Cocos2d-x trip _ 22] How do not enter the standby Cocos2d-x (screen stay awake do not lock screen unchanged black ......), Cocos2d-x_22
Original article, welcome to reprint, reprint Please note: article from [Han Jiang Gu Ye, Cocos2d-x travel series]
Blog: http://blog.csdn.net/qq446569365
The method is very simple, and a line of code can be easily done ......
The first is IOS implementation:
Add the following code to around 70 lines in the AppController. mm file:
[[UIApplicationsharedApplication] setIdleTimerDisabled: YES];
The Code is as follows:
// Set RootViewController to window if ([[UIDevice currentDevice]. systemVersion floatValue] <6.0) {// warning: addSubView doesn' t work on iOS6 [window addSubview: _ viewController. view];} else {// use this method on ios6 [window setRootViewController: _ viewController];} [window makeKeyAndVisible]; // prevent the IOS system from entering sleep [[UIApplication sharedApplication] setIdleTimerDisabled: YES]; // This is the line! // Hide the status bar [[UIApplication sharedApplication] setStatusBarHidden: true]; // IMPORTANT: Setting the GLView shocould be done after creating the RootViewController cocos2d: GLView * glview = cocos2d: GLView:: createWithEAGLView (eaglView); cocos2d: ctor: getInstance ()-> setOpenGLView (glview); cocos2d: Application: getInstance ()-> run ();
Android implementation:
The android implementation is also very simple. You can use the user-permission statement in the AndroidManifest. xml file:
Add the following code:
<Uses-permission android: name = "android. permission. WAKE_LOCK"/>
<Supports-screens android: anyDensity = "true" android: smallScreens = "true" android: normalScreens = "true" android: largeScreens = "true" android: xlargeScreens = "true"/> <uses-permission android: name = "android. permission. INTERNET "/> <uses-permission android: name =" android. permission. WAKE_LOCK "/> <! -- This line is --> </manifest>