How to Build A Simple iOS 10 Flashlight App For iPhone

0
Shares
How to Build A Simple iOS 10 Flashlight App For iPhone
5 (100%) 1 vote

Today, we’re going to build a simple iOS 10 best Flashlight app for iPhone. This demo contains absolutely no complex design. However, if you wish to add some interactive animations or something, you can design the flashlight app with a graphic design software such as Photoshop. best flashlight app

Let’s Get Started

Create a new project under file menu and select “Single View Application.”

soflashlight1

In the next tab, modify your project details and click on submit.

soflashlight2

Now, add a button in your Main.Storyboard ViewController

Set a click event “actionTorchClick”

Next, import AVFoundation in ViewController.swift

Declare a boolean variable ‘is Torch’ to turn ON/OFF the torch.

Var isTorch = false

Now integrate the code snippet to touch ON/OFF in “actionTorchClick” method.

@IBAction func actionTorchClick(sender: AnyObject) {

        

        guard let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) else { return }

        

        if device.hasTorch {

            isTourch = !isTourch

            do {

                try device.lockForConfiguration()

                

                if isTourch == true {

                    device.torchMode = .On

                } else {

                    device.torchMode = .Off

                }

                

                device.unlockForConfiguration()

            } catch {

                print("Torch is not working.")

            }

        } else {

            print("Torch not compatible with device.")

        }

    }

And Done!

Simple right? However, it’s also possible to adjust the flashlight’s brightness with couple of tweaks in the source code. And if you don’t know where the flashlight feature can be used, well the answer is, Photo editing apps.

Yes, if you might have already noticed that all of them provide an in-app camera with all features including flashlight control. So while developing a Photo or flashlight app for iPhone, it’s possible to include flashlight feature so that users can capture better quality pictures. And if you need to develop an iOS app from scratch, write down your app requirements, hire swift developer, and execute your startup plan.

Grab a free copy of iPhone Flashlight app demo from Github.

 
0
Shares
 

Want to Hire Expert Swift Developers? Contact Us Now