Code to turn flash on?

Discussion in 'iOS Programming' started by mikemanblah, Jul 6, 2010.

  1. macrumors regular

    Joined:
    Jul 15, 2009
    #1
    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

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    This usually means you have some kind of syntax error in the code prior to this error. Care to provide some code?
     
  3. thread starter macrumors regular

    Joined:
    Jul 15, 2009
    #3
    I dont have anything else written in before it, Its a fresh slate with one line of code
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Alright, then. Let's see that one line of code.
     
  5. thread starter macrumors regular

    Joined:
    Jul 15, 2009
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Did you try searching the Developer Documentation for "flash"?
     
  7. thread starter macrumors regular

    Joined:
    Jul 15, 2009
    #7
    I'm getting this

    Code:
    #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;
    @end
     
  8. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    You cannot assign values to variables in the @interface section. Only in the @implementation.
     
  9. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Plus, what the heck is UIImagePickerControllerCameraFlashModeOn?
     
  10. macrumors 603

    Joined:
    Aug 9, 2009
    #10
    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:
    http://developer.apple.com/iphone/l.../c_ref/UIImagePickerControllerCameraFlashMode

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

    Joined:
    Jul 15, 2009
    #11
    I'm 13 and i'm just starting out. What would i type instead? Thanks for all the help
     
  12. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    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

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #13
    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

    Joined:
    Aug 9, 2009
    #14
    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. thread starter macrumors regular

    Joined:
    Jul 15, 2009
    #15
    Well imma go reading up. I was trying to turn the flash on
     
  16. macrumors 603

    Joined:
    Aug 9, 2009
    #16
    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.
    http://forums.macrumors.com/showthread.php?t=962403

    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. thread starter macrumors regular

    Joined:
    Jul 15, 2009
    #17
    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