How can I prevent the display on an iOS device from dimming and turning off? [duplicate]

本秂侑毒 提交于 2019-12-17 15:13:26

问题


I'm diving into iOS development and am building my own alarm clock app to become familiar with platform and SDK. I've noticed some alarm clock apps in the app store keep the screen from dimming and/or turning off when their app is running. How is this implemented?


回答1:


Add this line of code on your application delegate:

Objective-C:

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift 2:

UIApplication.sharedApplication().idleTimerDisabled = true

Swift 3:

UIApplication.shared.isIdleTimerDisabled = true


来源:https://stackoverflow.com/questions/3436169/how-can-i-prevent-the-display-on-an-ios-device-from-dimming-and-turning-off

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