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

查看:138
本文介绍了如何防止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:

Objective-C:

Objective-C:

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift 2:

UIApplication.sharedApplication().idleTimerDisabled = true

Swift 3:

UIApplication.shared.isIdleTimerDisabled = true

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

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