如何防止 iOS 设备上的显示屏变暗和关闭? [英] How can I prevent the display on an iOS device from dimming and turning off?

查看:24
本文介绍了如何防止 iOS 设备上的显示屏变暗和关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在深入研究 iOS 开发,并正在构建自己的闹钟应用以熟悉平台和 SDK.我注意到应用商店中的一些闹钟应用会在应用运行时防止屏幕变暗和/或关闭.这是如何实施的?

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?

推荐答案

在您的应用程序委托中添加这行代码:

Add this line of code on your application delegate:

目标-C:

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

斯威夫特 2:

UIApplication.sharedApplication().idleTimerDisabled = true

斯威夫特 3、4 和5:

Swift 3, 4 & 5:

UIApplication.shared.isIdleTimerDisabled = true

这篇关于如何防止 iOS 设备上的显示屏变暗和关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆