添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

In this post we will be seeing how to prevent screen from sleeping in iOS.

So, let’s get started.

Copy the below line of code in viewDidLoad method in ViewController.Swift

override func viewDidLoad() {
   super.viewDidLoad()
   // Do any additional setup after loading the view, typically from a nib.
   UIApplication.shared.isIdleTimerDisabled = true
}

Run the application, the application will never go in sleep mode.

  • Related Articles
  • How to lock Screen Orientation programmatically in iOS?
  • How to change screen brightness programmatically in iOS?
  • How do I prevent an iOS device from going to sleep mode?
  • How to programmatically prevent scrolling in WebView of iOS?
  • How to prevent custom views from losing state across screen orientation changes ?
  • How to lock the screen to prevent scrolling in the Excel worksheet?
  • How to align views at the bottom of the screen in iOS
  • How to Ping External host from Swift in iOS?
  • How to create Picker programmatically from array in iOS?
  • How to Prevent Systems from Phishing Attacks?
  • How to Prevent Your Website from Hackers?
  • How to prevent form from being submitted?
  • How to prevent buttons from submitting forms in HTML?
  • How to prevent the browser from executing the default action in jQuery?
  • How to access RESTFul services from iOS/iPhone?
  • We make use of First and third party cookies to improve our user experience. By using this website, you agree with our Cookies Policy.