Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

masaniparesh

macrumors newbie
Original poster
Jan 26, 2011
1
0
Hi, I have written my first iPhone application FlashLight which turn on/off camera flash light. Following is the code for the same. It works fine except one issue. When I have flash on and it I press iPhone home button, it exit the application, turned off the flash light but when I start again it starts behaving weird. Sometimes I get black screen and at times it hangs up and respond very late. The other strange thing is if I wait few minutes and then restart the application works fine. I am sure there must be something to do memory release but I already been releasing session memory and also releasing captured AVSession in dealloc routine..! Not sure what could be wrong here. Could anyone please help me to find it out and let me know how could I debug the issue?

Code:
-(IBAction)submit:(id) sender {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    if ([device hasTorch] && [device hasFlash]){

        if (device.torchMode == AVCaptureTorchModeOff) {
            AVCaptureDeviceInput *flashInput = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];

            AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];


            AVCaptureSession *session = [[AVCaptureSession alloc] init];

            [session beginConfiguration];

            [device lockForConfiguration:nil];

            [device setTorchMode:AVCaptureTorchModeOn];

            [device setFlashMode:AVCaptureFlashModeOn];

            [session addInput:flashInput];

            [session addOutput:output];

            [device unlockForConfiguration];

            [output release];

            [session commitConfiguration];

            [session startRunning];

            [self setAVSession:session];
            [session release];
        }
        else {
            [AVSession stopRunning];
       }
   }
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.