简体   繁体   中英

How do we increase or decrease brightness of a tvOS app using Swift 3? Also, how do we implement a customized sleep timer here?

I am building a tvOS app using swift3. It is an app where video plays in a loop with sounds. I need to include brightness control, Speed control and a sleep timer.

This is my code:

@IBOutlet var downBtn: UIButton!

    @IBOutlet var upBtnn: UIButton!



 private var brightness: CGFloat?
    var scale: Double = 0
    let maxScale: Double = 1


 @IBAction func increaseBtn(_ sender: Any) {


        if scale > maxScale {
            return
        }

        scale += 0.10
        uiscreenbrightness(UInt(scale))

    }

    @IBAction func decreaseBright(_ sender: Any) {


        if scale <= 0 {
            return
        }

        scale -= 0.10
        uiscreenbrightness(UInt(scale))

    }

    func uiscreenbrightness(_ scale: UInt) {

//       UIScreen.main.brightness = CGFloat(scale)


    }

But this gives me an error " Brightness is unavailable". How do I include the brightness functionality?

Also, this app has a customized timer functionality. So when the user sets a time, the TV will sleep after that. Is it possible to do this?

Thanks for your help :)

You cannot set the brightness. From here , the section about the SDK only has iOS 5+ 在此输入图像描述

Personally, I think you cannot sleep the TV itself. Look at this question: Programmatically sleep Apple TV on tvos , there are no answers even after such a long time. A basic google search returned completely irrelevant results.

As with the iPhone, this may be updated later and an API may be created. I will edit this once an API is available.

EDIT: You may want to try to give feedback to apple (suggestion only)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM