How to turn ON/OFF camera flashlight in iOS, this is our main objective. There are so many users; those are using turn on flashlight with one button and turn off flashlight with another. But here I want to do it with a single button only.


Follow the below mentioned step in order to implement flash light in iOS:


Step 1 Create Xcode Project

First of all create xCode project named it FlashLightDemo and saved it. This project will contain one View Controller, which will become main view controller.


Step 2 Add frameworks

To implement flash light we required AVFoundation framework. The AVFoundation framework is responsible for management and interaction with audio-visual media in iOS applications. AVFoundation framework needs to link to your application.

For that go to project, now select build Phases tab, and then go to Link Binary with Library, Add framework as following. 

av foundation framework


Step 3 Design UI

Design User Interface describe as per the following screen. 

user interface


Step 4 Code for Flashing

Write following function to the tap event of above mentioned button.

- (IBAction)btnFlashOnClicked:(id)sender
    AVCaptureDevice *flashLight = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if ([flashLight isTorchAvailable] && [flashLight isTorchModeSupported:AVCaptureTorchModeOn])
        BOOL success = [flashLight lockForConfiguration:nil];
        if (success)
            if ([flashLight isTorchActive])
                [btnFlash setTitle:@"TURN ON" forState:UIControlStateNormal];
                [flashLight setTorchMode:AVCaptureTorchModeOff];
                [btnFlash setTitle:@"TURN OFF" forState:UIControlStateNormal];
                [flashLight setTorchMode:AVCaptureTorchModeOn];
            [flashLight unlockForConfiguration];

I hope you found this blog helpful while working Flashlight with one button. Let me know if you have any questions or concerns regarding iOS, please put a comment here and we will get back to you ASAP.

Got an Idea of iPhone App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best iPhone App Development Company in India.

I am iOS developer, as a developer my basic goal is continue to learn and improve my development skills , to make application more user friendly.

face mask Belial The Demon Headgear Pocket Staff Magic