iPhone - phone goes to sleep even if idleTimerDisabled is YES

前端 未结 9 1381
难免孤独
难免孤独 2020-11-30 03:45

I am using this in my appdelegate\'s applicationDidFinishLaunching: method to make sure the iPhone doesn\'t go to sleep during the time the app is open

[appl         


        
9条回答
  •  鱼传尺愫
    2020-11-30 04:10

    Instead of Appdelegate, It is better to use it in a specific view controller in which you want screen light to be alive.

    Swift 5.0 Version:

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        UIApplication.shared.isIdleTimerDisabled = true
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        UIApplication.shared.isIdleTimerDisabled = false
    }
    

提交回复
热议问题