Build Custom Camera App Using Custom Framework

0
Shares
Build Custom Camera App Using Custom Framework
1 (20%) 1 vote

Check This Simple Custom Camera Implementation that Adds Different Functionality To Your App

Since its first model, the iPhone has shipped with a camera. However, the only way to integrate the camera into an app by using its SDKs UIImagePickerController.

With the introduction of the AVFoundation framework, iPhone app developers get more flexibility.

In this article, we will see how one common module uses in different applications in iOS.

If we want to distribute that module to the social world and don’t want to reveal that logic behind it, then we need to create the framework of the code.

Here, we are going to create one simple custom camera implementation as the framework that we can use in any application to add different functionalities like shutter speed, Video recording, slow-motion recording, Photo timer, live filters.

1. Creating a project from scratch

Since Xcode 7, there is a built-in option to create a dynamic framework project. You should use this option if you need to create a framework project from scratch:

2. For further information how we made this SDK/Framework for the custom camera, You can visit the below link:

https://github.com/spaceotech/Camera-SDK

# We hope that you already went through the framework portion. You have to generate a .framework file from building our code available at GitHub. Now you have framework file so let’s start integration in the project.

 

Integrate the framework in external app for Development

 

1. Create a new project and drag SOCameraManager.framework into the Root folder of your project. Then, Go to your project target, click on the “Build Settings” tab, and Add “SOCameraManager.framework” to Embed Binaries in the app’s General setting.

 

2. Create UI/UX for a custom camera.

# Further, let’s see how to use a framework at the code level.

 

3. ViewController.swift

import UIKit
import SOCameraManager

class ViewController: UIViewController {
// MARK: - Constants
let cameraManager = SOCameraManager()

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
cameraManager.showAccessPermissionPopupAutomatically = false

let currentCameraState = cameraManager.currentCameraStatus()
if currentCameraState == .NotDetermined {

} else if (currentCameraState == .Ready) {
addCameraToView()
}
if !cameraManager.hasFlash {
btnFlash.enabled = false
btnFlash.setTitle("On", forState: UIControlState.Normal)
}
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.hidden = true
cameraManager.resumeCaptureSession()
}

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
cameraManager.stopCaptureSession()
}

// MARK: - Add camera to view
private func addCameraToView() {
cameraManager.addPreviewLayerToView(cameraView, newCameraOutputMode: SOCameraOutputMode.StillImage)
cameraManager.showErrorBlock = { [weak self] (erTitle: String, erMessage: String) -> Void in

let alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (alertAction) -> Void in }))
self?.presentViewController(alertController, animated: true, completion: nil)
}
}

// MARK: - Change Flash Mode
@IBAction func btnFlashClicekd(sender: AnyObject) {
switch (cameraManager.changeFlashMode()) {
case .Off:
sender.setTitle("Off", forState: UIControlState.Normal)
case .On:
sender.setTitle("On", forState: UIControlState.Normal)
case .Auto:
sender.setTitle("Auto", forState: UIControlState.Normal)
}
}
// MARK: - Camera capture photo
@IBAction func btnCaptureClicked(sender: AnyObject) {
cameraManager.capturePictureWithCompletition({ (image, error) -> Void in
let vc: ImageViewController? = self.storyboard?.instantiateViewControllerWithIdentifier("ImageVC") as? ImageViewController
if let validVC: ImageViewController = vc {
if let capturedImage = image {
validVC.image = capturedImage
self.navigationController?.pushViewController(validVC, animated: true)
}
}
})
}

// MARK: - Rotate camera front and back
@IBAction func btnCameraFlipClicked(sender: AnyObject) {

cameraManager.cameraDevice = cameraManager.cameraDevice == SOCameraDevice.Front ? SOCameraDevice.Back : SOCameraDevice.Front
switch (cameraManager.cameraDevice) {
case .Front:
sender.setTitle("Front", forState: UIControlState.Normal)
case .Back:
sender.setTitle("Back", forState: UIControlState.Normal)
}
}
// MARK: - Ask permission to user
@IBAction func askForCameraPermissions(sender: UIButton) {
cameraManager.askUserForCameraPermissions({ permissionGranted in
if permissionGranted {
self.addCameraToView()
}
})
}
}

We have used this simple custom camera implementation in many of our applications like TextOnPhoto, TextOnVideo, VideoEditor, Photoblur. Our iPhone app development team have also used the same camera implementation in SquareSized app to add functionality like posting an entire photo on Instagram.

We have optimized SquareSized for iOS 9, iPhone 6s and iPhone 6s Plus. Right now, this application is used by more than 5 million people worldwide to post photos on Instagram! We also have integrated features of adding borders on each side of the photos, filters, text and shapes, and backgrounds.

Apart from this dedicated iOS app developers, we do have a dedicated team for custom web app development. If you have any question regarding it, feel free to contact us.

 
0
Shares
 

Want to Make Camera App or Implementation? Talk to our iPhone developers through this form