打开Led闪光灯

#import <AVFoundation/AVFoundation.h>
-(IBAction)btnClicked:(id)sender
{
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];  
    if ([device hasTorch])
    {  
        if(AVCaptureTorchModeOn==[device torchMode])
        {
            [btn setTitle:@"Turn On" forState:UIControlStateNormal];
            [device lockForConfiguration:nil];  
            [device setTorchMode: AVCaptureTorchModeOff];  
            [device unlockForConfiguration]; 
        }
        else if(AVCaptureTorchModeOff==[device torchMode])
        {
            [btn setTitle:@"Turn Off" forState:UIControlStateNormal];
            [device lockForConfiguration:nil];  
            [device setTorchMode: AVCaptureTorchModeOn];  
            [device unlockForConfiguration]; 
        }
    }  
}

Comments are closed.