[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

Source: Internet
Author: User

[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>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.