Search Unity

Phone Flashlight not working with Vuforia

Discussion in 'Vuforia' started by dccoo, May 8, 2018.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    I used the Vuforia code CameraDevice.Instance.SetFlashTorchMode(true) but it always return false (and never turns the flashlight on), but my phone (iPhone SE) has flashlight and even a lantern functionality, and I couldn't find any documentation that explains this happens or how to fix it.

    I didn't configure anything before calling that piece of code, I just called it. Maybe there is some initialisation required? Something like var vuforia = Vuforia.Init() or anything like this (in the Start() or Awake() methods)?

    What can it be? Is there a way to fix it? Is there a better (or just another) way to turn the device's flashlight on?

    Thank you!
     
  2. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    This is the correct code for enabling and disabling the flash. Are you running this before initializing Vuforia?

    Our Core Samples have an example of enabling and disabling this value through UI, could you review that and see if you are missing something?
     
  3. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    Hey, Vuforia-Strasza, thanks for answering!

    I added CameraSettings.cs (a class from Vuforia core samples) into my GameObject (just to make sure everything would be configured just like the core samples) and when I want to turn the flash on, I call the method SwitchFlashTorch. As I said before, I'm using an iPhone SE, which has flashlight and even lantern functionality.

    Nothing happens though, xcode's console shows this:

    Toggle flash ON FAILED
    Vuforia.CameraDevice:SetFlashTorchMode(Boolean)
    MyAppName.Utils.CameraSettings:SwitchFlashTorch(Boolean)
    UnityEngine.Events.UnityEvent:Invoke()
    UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    UnityEngine.EventSystems.StandaloneInputModule: ProcessTouchPress(PointerEventData, Boolean, Boolean)
    UnityEngine.EventSystems.StandaloneInputModule: ProcessTouchEvents()
    UnityEngine.EventSystems.StandaloneInputModule: Process()


    No idea how to proceed... is this class (CameraSettings.cs) the only class necessary to fully initialize Vuforia? I only imported this class into my project and into my GameObject.
     
    Last edited: May 9, 2018
  4. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    So... any news? I couldn't solve it yet :(
     
  5. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    I'm unclear what you mean by this. Are you using only this class and no other Vuforia code? Did you look at how CameraSettings.cs is used in the context of the sample?
     
  6. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    I meant: I imported only this class (CameraSettings.cs) from the core samples, no other class from the core samples was imported to my project.

    I didn't look at the whole code of CameraSettings.cs, because it didn't seem to have other dependencies. The class, by itself, was successfully compiled, so I thought it would do the job all alone.

    I added CameraSettings.cs as a component of an object (that deals with the camera), and when I need to turn the flashlight ON, I do GetComponent<CameraSettings>().SwitchFlashTorch(ON) from another code of this object.
     
  7. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    I forgot to mention, I searched all around the core samples and couldn't find any scene where it's possible to deal with the flashlight through UI.
     
  8. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @dccoo I've tested the Core Samples in Unity 2018.1.0f2 with Vuforia 7.1.34 and the flash is working on the iPhone SE. You can access the option while running the app by double tapping the screen. This will give you options for flash, extended tracking, and front camera when available.
     
    dccoo likes this.
  9. jemonsuarez

    jemonsuarez

    Joined:
    Sep 24, 2012
    Posts:
    151
    Hi @Vuforia-Strasza, I'm using Unity 2018.2.0f2 and Vuforia 7.2.24 (downloaded automatically from Unity editor) and the Vuforia.CameraDevice.SetFlashTorchMode() method seems not exists any more, but it's in the Vuforia documentation.
    Can you point me please in the right direction in order to find it? I've tried switching the build platform and exploring other classes but it still not showing.
    Best regards.
     
  10. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    This API still exists in 7.2.X. You'll need to do CameraDevice.Instance.SetFlashTorchMode() however. This is used in the Core Samples if you'd like to see an example.
     
  11. jemonsuarez

    jemonsuarez

    Joined:
    Sep 24, 2012
    Posts:
    151
    Thanks for the answer, I've used the interface successfully while the Vuforia camera was active, but when the vuforia camera is not working (that means i'm using some Unity WebCamTexture) the flash torch is not responding.
    That's odd, but it works if your application is AR only. Sadly I'm using both, switching from one to the other, so it's useless.
    Thanks again.
     
  12. meedabit

    meedabit

    Official Vuforia Employee Vuforia

    Joined:
    Dec 8, 2016
    Posts:
    266
    Hello @jemonsuarez,

    The camera must be initialized by Vuforia in order for Vuforia APIs to control the camera. Vuforia APIs are only an abstraction of platform camera APIs. Thus, we are calling the same APIs as the platform OS.

    Thanks,
    Vuforia Engine Support
     
  13. junaidjoosani

    junaidjoosani

    Joined:
    Oct 29, 2018
    Posts:
    1
    Toggle flash ON FAILED

    Same issue

    Unity version 2018.2.0f2
    Vuforia version 8.0.10

    code to turn of light
    " Vuforia.CameraDevice.Instance.SetFlashTorchMode(true);" but it returns Toggle flash ON FAILED
     
  14. meedabit

    meedabit

    Official Vuforia Employee Vuforia

    Joined:
    Dec 8, 2016
    Posts:
    266