prender prende linterna funciona enciende como carga apagar activar objective-c cocoa-touch ios4 camera-flash ios-camera

objective c - prende - ¿Cómo encender y apagar la cámara del iPhone?



iphone no enciende y no carga (3)

¿Cómo puedo activar / desactivar el flash LED de la cámara del iPhone programáticamente?


Combiné el temporizador con el código anterior. Me funcionó ...

- (void)viewDidLoad { [super viewDidLoad]; myTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(toggleFlashlight) userInfo:nil repeats:YES]; // Do any additional setup after loading the view from its nib. } - (void) toggleFlashlight { // check if flashlight available Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice"); if (captureDeviceClass != nil) { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if ([device hasTorch] && [device hasFlash]){ [device lockForConfiguration:nil]; if (device.torchMode == AVCaptureTorchModeOff) { [device setTorchMode:AVCaptureTorchModeOn]; [device setFlashMode:AVCaptureFlashModeOn]; //torchIsOn = YES; } else { [device setTorchMode:AVCaptureTorchModeOff]; [device setFlashMode:AVCaptureFlashModeOff]; // torchIsOn = NO; } [device unlockForConfiguration]; } } }


va a necesitar un par de declaraciones vacías (doSOmethingfoo y showAcitivtyfoo) y un NSTimer (mytimer) en su archivo .h, junto con algún código

-(void)doSmethingfoo { myTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showActivityfoo) userInfo:nil repeats:YES]; }


#import <AVFoundation/AVFoundation.h>

...

- (void) turnTorchOn: (bool) on { // check if flashlight available Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice"); if (captureDeviceClass != nil) { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if ([device hasTorch] && [device hasFlash]){ [device lockForConfiguration:nil]; if (on) { [device setTorchMode:AVCaptureTorchModeOn]; [device setFlashMode:AVCaptureFlashModeOn]; //torchIsOn = YES; //define as a variable/property if you need to know status } else { [device setTorchMode:AVCaptureTorchModeOff]; [device setFlashMode:AVCaptureFlashModeOff]; //torchIsOn = NO; } [device unlockForConfiguration]; } } }