I am using AVCapture frame work to set blinking flash light at the time of taking photo from camera. In this method I am getting flash light blinking effect for a few seconds but then it is getting crashed.
Below is the code which I have done.
-(IBAction) a
{
_picker = [[UIImagePickerController alloc] init];
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
_picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
_picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
_picker.showsCameraControls = YES;
_picker.navigationBarHidden =YES;
_picker.toolbarHidden = YES;
_picker.wantsFullScreenLayout = YES;
[_picker takePicture];
// Insert the overlay
OverlayViewController *overlay = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
overlay.pickerReference = _picker;
_picker.cameraOverlayView = overlay.view;
_picker.delegate = (id)self;
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(flashLight_On_Off) userInfo:nil repeats:YES];
[self presentModalViewController:_picker animated:NO];
}
- (void)flashLight_On_Off
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
{
if ([device hasFlash] == YES)
{
[device lockForConfiguration:nil];
if (bulPicker == FALSE)
{
[device setTorchMode:AVCaptureTorchModeOn];
bulPicker = TRUE;
}
else
{
[device setTorchMode:AVCaptureTorchModeOff];
bulPicker = FALSE;
}
[device unlockForConfiguration];
}
}
}
Is there any problem? Any other method to get the solution? I have to also stop blinking after taking image before pressing use button.
Please suggest me appropriate solution.
If I recall correctly the Cocoa naming convention, any method except
- alloc,- copyand- mutableCopyreturns an autoreleased object. In this case,gets called 10 times a second, and each time it’s autoreleased. It means that it may not be released immediately, so it will start eating up your RAM and the OS eventually detects this and kills the process of your app.
What you should do is wrap these kinds of operations into an autorelease pool if you know beforehand that they’ll be called a lot.