detecting if iPhone is in a dark room

后端 未结 6 1604
独厮守ぢ
独厮守ぢ 2020-11-30 03:40

Is there a way to use the iPhone proximity sensor to detect whether the phone is in a room with no light?

This question seems to imply that this is not possible...Do

6条回答
  •  旧巷少年郎
    2020-11-30 03:55

    There is much simpler solution for this if anyone needs. Use screen brightness to detect the light conditions:

    0 - 0.3 (Dark)

    0.4 - 1 (Bright)

    Tweak as needed:

    switch UIScreen.main.brightness {
        case 0 ... 0.3:
            print("LOW LIGHT")
        default:
            print("ENOUGH LIGHT")
        }
    

提交回复
热议问题