如何防止 iOS 设备上的显示屏变暗和关闭?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3436169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I prevent the display on an iOS device from dimming and turning off?
提问by BeachRunnerFred
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?
我正在深入研究 iOS 开发,并正在构建我自己的闹钟应用程序以熟悉平台和 SDK。我注意到应用程序商店中的一些闹钟应用程序会在其应用程序运行时防止屏幕变暗和/或关闭。这是如何实施的?
回答by I?igo Beitia
Add this line of code on your application delegate:
在您的应用程序委托上添加这行代码:
Objective-C:
目标-C:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Swift 2:
斯威夫特 2:
UIApplication.sharedApplication().idleTimerDisabled = true
Swift 3, 4 & 5:
斯威夫特 3、4 和 5:
UIApplication.shared.isIdleTimerDisabled = true