ios – Auto flash on/off behaving bizarre

[ad_1]

I’ve applied auto flash on-off utilizing ARKit as a result of I am utilizing ARKit on the identical display screen.

Implementation:

func session(_ session: ARSession, didUpdate body: ARFrame) {
    let ambientIntensity = body.lightEstimate?.ambientIntensity
    print(ambientIntensity)

    if ambientIntensity < 180 {
        // room is darkish
        turnOnTorch()
    } else {
        // mild is sufficient
        turnOffTorch()
    }

Right here I am utilizing ARFrame’s lightEstimate to get mild depth from the present surroundings.

Drawback:
When ambientIntensity variable’s worth is lower than 180 then, the flash will probably be turned on. However when this delegate methodology calls itself and it’ll see that, oh sure we now have the lights within the surroundings, however right here we’re getting mild from the flashlight, not the daylight. So ambientIntensity variable’s worth will probably be greater than 180, so now the flashlight will probably be off.
So this factor will go on and on. The flashlight will repeatedly activate and off itself.

I’ve seen one other answer is that some individuals are setting the sunshine upon the display screen brightness. However from my standpoint, that’s the unsuitable strategy.

Is there some other answer is there that I can apply right here? Thanks upfront.

[ad_2]

Leave a Reply