Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Activate iPhone 4 LED Light

I know this is extremely far fetched haha, but would anyone be willing to explain how to active the iPhone 4's LED. Any advice or help would be appreciated. Thanks!

— asked July 16th 2010 by Ross Waycaster
  • flash
  • iphone4
  • led
  • light
  • mobile
  • module
  • os4
1 Comment
  • uhh… like a module maybe?

    — commented July 16th 2010 by Ross Waycaster

4 Answers

  • Sorry about that. I should have followed up, since I was looking at the source code, not the documentation. If you compile for iOS 4.0 and above, there's a number of useful things.

    Ti.Media has 3 constants regarding the flash:

    • Ti.Media.CAMERA_FLASH_ON

    Use these with the Ti.Media.CameraFlashMode property, which is readable and writable.

    There are also 2 constants and an array regarding which camera:

    • Ti.Media.CAMERA_FRONT
    • Ti.Media.CAMERA_REAR

    Additionally, the Ti.Media.availableCameras property is a read-only array listing what cameras the device has.

    To determine which camera is currently chosen, use the read-only Ti.Media.Camera property. Use the Ti.Media.switchCamera function to switch cameras.

    — answered August 10th 2010 by Blain Hamon
    • Thank you Blain, trying to light the led but can't get this working…
      Can you post an simple example code to explain this?

      iOS 4.0.1 - Titanium Developper 1.2.1 - SDK 1.4.0

      — commented August 19th 2010 by Nicolas Arcay Bermejo
    • Here is the code from the Kitchen Sink:
      Ti.Media.cameraFlashMode = Ti.Media.CAMERA_FLASH_ON;
      I think the camera has to be on for it to work though.

      — commented September 14th 2010 by Robert Reinhard
    • This appears to no longer work in SDK 1.6.1 – has the code changed in some way?

      — commented April 11th 2011 by Andrew Skinner
  • http://www.iphonedevsdk.com/forum/iphone-sdk-development/51651-access-camera-flash-2.html

    Here is the code to make it work from Xcode. A build and run from xcode and the light turns on, but I have no idea how to get this to work from Titanium.

    Someone please help!

    — answered July 16th 2010 by Ross Waycaster
  • I have asked this on webinar presented by Kevin W. a week ago and they said the front-facing camera and led flash is supported under 1.4 Titanium Mobile. I looked at the 1.4 API ( https://developer.appcelerator.com/apidoc/mobile/1.4 ) but cant find any reference to front-facing cam or the led flash properties.

    — answered August 9th 2010 by Felipe Apostol
  • Hey guys!

    For the flash stuff you have to check the property:
    Ti.Media.cameraFlashMode (case sensitive)

    To change it you can use Ti.Media.setCameraFlashMode(PARAM) .

    PARAM could be:

    Unfortunately you can't start the led and use it as a torch, you can only control the camera flash handling (on, off, auto) while taking a photo.

    — answered June 21st 2011 by Jan Lohmer
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.