1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Code to turn flash on?

Discussion in 'iPhone/iPad Programming' started by mikemanblah, Jul 6, 2010.

  1. macrumors regular

    What is the code to turn the iphone 4 camera flash on?

    Also what does this error mean

    error: expected specifier-qualifier-list before '@' token
  2. Moderator


    Staff Member

    This usually means you have some kind of syntax error in the code prior to this error. Care to provide some code?
  3. macrumors regular

    I dont have anything else written in before it, Its a fresh slate with one line of code
  4. Moderator


    Staff Member

    Alright, then. Let's see that one line of code.
  5. macrumors regular

    i will in a sec
    Anyone got the flash api?
  6. Moderator


    Staff Member

    Did you try searching the Developer Documentation for "flash"?
  7. macrumors regular

    I'm getting this

    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <UIKit/UIImagePickerController.h>
    @interface Mainview : UIResponder {
    UIImagePickerControllerCameraFlashModeOn   = 1 
    (: error: expected specifier-qualifier-list before 'UIImagePickerControllerCameraFlashModeOn')
    typedef NSInteger UIImagePickerControllerCameraFlashMode;
  8. Moderator


    Staff Member

    You cannot assign values to variables in the @interface section. Only in the @implementation.
  9. Moderator


    Staff Member

    Plus, what the heck is UIImagePickerControllerCameraFlashModeOn?
  10. macrumors 603

    You need a typename before UIImagePickerControllerCameraFlashModeOn.

    If you intend to use UIImagePickerControllerCameraFlashMode as the type of UIImagePickerControllerCameraFlashModeOn, then you need to place it before the typedef is used. C and Objective-C don't support deferred definitions of any types. The typename must be defined before the point of its first use.

    Also, the names you're using have already been defined:

    I get the feeling you don't know how to use enum types.
  11. macrumors regular

    I'm 13 and i'm just starting out. What would i type instead? Thanks for all the help
  12. Moderator


    Staff Member

    I'm gonna suggest instead that it's time to step away from the real coding and go learn the basics of Objective-C.
  13. macrumors 603

    Or plain C, since that's where Obj C gets its types and type syntax from, plus there are a ton more books available on learning C, probably at your local library for free.
  14. macrumors 603

    No one knows what you'd type instead. You haven't explained what you want to do. No one can write code effectively without knowing what it's expected to do.

    In any case, if you have to ask what to type, then you're probably not ready to type any code. You need to do more reading. You can't sit down in the cockpit of a fighter jet and expect to fly it without some training.

    We can't read your mind. We can't see your screen. All we know about you and your work is what you tell us in this forum.

    If you haven't told us what book or tutorial you're using, then you can't expect advice on a better one. If you're not using a book or tutorial, there are stickies at the top of this forum you should read.
  15. macrumors regular

    Well imma go reading up. I was trying to turn the flash on
  16. macrumors 603

    Yes, that was obvious. What's not so obvious is the larger context of what you're trying to do.

    The UIImagePickerControllerCameraFlashMode type, and its 3 values (off, on, and auto) are used to specify how the flash behaves when taking a picture with the camera. But you asked in another thread about how to turn on the flash LED to use it as "not a flashlight", which is a completely different thing than using it with the camera.

    So you're still not really explaining what you want to do in a way that someone can give useful suggestions.

    Other things that aren't obvious are the extent of your programming experience, and exactly what you're reading that you hope will teach you how to make a flashlight using the LED.
  17. macrumors regular

    Just so i can have a test project, whats the iphone documentation page for the led flash that does not require opening of the camera app

Share This Page