update demo to support swift 3
This commit is contained in:
parent
0267cc2664
commit
206bce0e94
|
|
@ -206,6 +206,7 @@
|
|||
TargetAttributes = {
|
||||
454C1F4019E82E2500C81915 = {
|
||||
CreatedOnToolsVersion = 6.0.1;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
D71DE8801AD677A7001E62F1 = {
|
||||
CreatedOnToolsVersion = 6.3;
|
||||
|
|
@ -398,6 +399,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
|
@ -410,6 +412,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(application: UIApplication) {
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(application: UIApplication) {
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(application: UIApplication) {
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(application: UIApplication) {
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class ImageViewController: UIViewController {
|
|||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.navigationController?.navigationBar.hidden = false
|
||||
self.navigationController?.navigationBar.isHidden = false
|
||||
|
||||
if let validImage = self.image {
|
||||
self.imageView.image = validImage
|
||||
|
|
|
|||
|
|
@ -33,32 +33,32 @@ class ViewController: UIViewController {
|
|||
|
||||
cameraManager.showAccessPermissionPopupAutomatically = false
|
||||
|
||||
askForPermissionsButton.hidden = true
|
||||
askForPermissionsLabel.hidden = true
|
||||
askForPermissionsButton.isHidden = true
|
||||
askForPermissionsLabel.isHidden = true
|
||||
|
||||
let currentCameraState = cameraManager.currentCameraStatus()
|
||||
|
||||
if currentCameraState == .NotDetermined {
|
||||
askForPermissionsButton.hidden = false
|
||||
askForPermissionsLabel.hidden = false
|
||||
} else if (currentCameraState == .Ready) {
|
||||
if currentCameraState == .notDetermined {
|
||||
askForPermissionsButton.isHidden = false
|
||||
askForPermissionsLabel.isHidden = false
|
||||
} else if (currentCameraState == .ready) {
|
||||
addCameraToView()
|
||||
}
|
||||
if !cameraManager.hasFlash {
|
||||
flashModeButton.enabled = false
|
||||
flashModeButton.setTitle("No flash", forState: UIControlState.Normal)
|
||||
flashModeButton.isEnabled = false
|
||||
flashModeButton.setTitle("No flash", for: UIControlState())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override func viewWillAppear(animated: Bool) {
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
navigationController?.navigationBar.hidden = true
|
||||
navigationController?.navigationBar.isHidden = true
|
||||
cameraManager.resumeCaptureSession()
|
||||
}
|
||||
|
||||
override func viewWillDisappear(animated: Bool) {
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
cameraManager.stopCaptureSession()
|
||||
}
|
||||
|
|
@ -66,42 +66,42 @@ class ViewController: UIViewController {
|
|||
|
||||
// MARK: - ViewController
|
||||
|
||||
private func addCameraToView()
|
||||
fileprivate func addCameraToView()
|
||||
{
|
||||
cameraManager.addPreviewLayerToView(cameraView, newCameraOutputMode: CameraOutputMode.VideoWithMic)
|
||||
cameraManager.addPreviewLayerToView(cameraView, newCameraOutputMode: CameraOutputMode.videoWithMic)
|
||||
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 }))
|
||||
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)
|
||||
self?.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - @IBActions
|
||||
|
||||
@IBAction func changeFlashMode(sender: UIButton)
|
||||
@IBAction func changeFlashMode(_ sender: UIButton)
|
||||
{
|
||||
switch (cameraManager.changeFlashMode()) {
|
||||
case .Off:
|
||||
sender.setTitle("Flash Off", forState: UIControlState.Normal)
|
||||
case .On:
|
||||
sender.setTitle("Flash On", forState: UIControlState.Normal)
|
||||
case .Auto:
|
||||
sender.setTitle("Flash Auto", forState: UIControlState.Normal)
|
||||
case .off:
|
||||
sender.setTitle("Flash Off", for: UIControlState())
|
||||
case .on:
|
||||
sender.setTitle("Flash On", for: UIControlState())
|
||||
case .auto:
|
||||
sender.setTitle("Flash Auto", for: UIControlState())
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func recordButtonTapped(sender: UIButton) {
|
||||
@IBAction func recordButtonTapped(_ sender: UIButton) {
|
||||
|
||||
switch (cameraManager.cameraOutputMode) {
|
||||
case .StillImage:
|
||||
case .stillImage:
|
||||
cameraManager.capturePictureWithCompletion({ (image, error) -> Void in
|
||||
if let errorOccured = error {
|
||||
self.cameraManager.showErrorBlock(erTitle: "Error occurred", erMessage: errorOccured.localizedDescription)
|
||||
self.cameraManager.showErrorBlock("Error occurred", errorOccured.localizedDescription)
|
||||
}
|
||||
else {
|
||||
let vc: ImageViewController? = self.storyboard?.instantiateViewControllerWithIdentifier("ImageVC") as? ImageViewController
|
||||
let vc: ImageViewController? = self.storyboard?.instantiateViewController(withIdentifier: "ImageVC") as? ImageViewController
|
||||
if let validVC: ImageViewController = vc {
|
||||
if let capturedImage = image {
|
||||
validVC.image = capturedImage
|
||||
|
|
@ -110,51 +110,51 @@ class ViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
})
|
||||
case .VideoWithMic, .VideoOnly:
|
||||
sender.selected = !sender.selected
|
||||
sender.setTitle(" ", forState: UIControlState.Selected)
|
||||
sender.backgroundColor = sender.selected ? UIColor.redColor() : UIColor.greenColor()
|
||||
if sender.selected {
|
||||
case .videoWithMic, .videoOnly:
|
||||
sender.isSelected = !sender.isSelected
|
||||
sender.setTitle(" ", for: UIControlState.selected)
|
||||
sender.backgroundColor = sender.isSelected ? UIColor.red : UIColor.green
|
||||
if sender.isSelected {
|
||||
cameraManager.startRecordingVideo()
|
||||
} else {
|
||||
cameraManager.stopVideoRecording({ (videoURL, error) -> Void in
|
||||
if let errorOccured = error {
|
||||
self.cameraManager.showErrorBlock(erTitle: "Error occurred", erMessage: errorOccured.localizedDescription)
|
||||
self.cameraManager.showErrorBlock("Error occurred", errorOccured.localizedDescription)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func outputModeButtonTapped(sender: UIButton) {
|
||||
@IBAction func outputModeButtonTapped(_ sender: UIButton) {
|
||||
|
||||
cameraManager.cameraOutputMode = cameraManager.cameraOutputMode == CameraOutputMode.VideoWithMic ? CameraOutputMode.StillImage : CameraOutputMode.VideoWithMic
|
||||
cameraManager.cameraOutputMode = cameraManager.cameraOutputMode == CameraOutputMode.videoWithMic ? CameraOutputMode.stillImage : CameraOutputMode.videoWithMic
|
||||
switch (cameraManager.cameraOutputMode) {
|
||||
case .StillImage:
|
||||
cameraButton.selected = false
|
||||
cameraButton.backgroundColor = UIColor.greenColor()
|
||||
sender.setTitle("Image", forState: UIControlState.Normal)
|
||||
case .VideoWithMic, .VideoOnly:
|
||||
sender.setTitle("Video", forState: UIControlState.Normal)
|
||||
case .stillImage:
|
||||
cameraButton.isSelected = false
|
||||
cameraButton.backgroundColor = UIColor.green
|
||||
sender.setTitle("Image", for: UIControlState())
|
||||
case .videoWithMic, .videoOnly:
|
||||
sender.setTitle("Video", for: UIControlState())
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func changeCameraDevice(sender: UIButton) {
|
||||
@IBAction func changeCameraDevice(_ sender: UIButton) {
|
||||
|
||||
cameraManager.cameraDevice = cameraManager.cameraDevice == CameraDevice.Front ? CameraDevice.Back : CameraDevice.Front
|
||||
cameraManager.cameraDevice = cameraManager.cameraDevice == CameraDevice.front ? CameraDevice.back : CameraDevice.front
|
||||
switch (cameraManager.cameraDevice) {
|
||||
case .Front:
|
||||
sender.setTitle("Front", forState: UIControlState.Normal)
|
||||
case .Back:
|
||||
sender.setTitle("Back", forState: UIControlState.Normal)
|
||||
case .front:
|
||||
sender.setTitle("Front", for: UIControlState())
|
||||
case .back:
|
||||
sender.setTitle("Back", for: UIControlState())
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func askForCameraPermissions(sender: UIButton) {
|
||||
@IBAction func askForCameraPermissions(_ sender: UIButton) {
|
||||
|
||||
cameraManager.askUserForCameraPermission({ permissionGranted in
|
||||
self.askForPermissionsButton.hidden = true
|
||||
self.askForPermissionsLabel.hidden = true
|
||||
self.askForPermissionsButton.isHidden = true
|
||||
self.askForPermissionsLabel.isHidden = true
|
||||
self.askForPermissionsButton.alpha = 0
|
||||
self.askForPermissionsLabel.alpha = 0
|
||||
if permissionGranted {
|
||||
|
|
@ -163,15 +163,15 @@ class ViewController: UIViewController {
|
|||
})
|
||||
}
|
||||
|
||||
@IBAction func changeCameraQuality(sender: UIButton) {
|
||||
@IBAction func changeCameraQuality(_ sender: UIButton) {
|
||||
|
||||
switch (cameraManager.changeQualityMode()) {
|
||||
case .High:
|
||||
sender.setTitle("High", forState: UIControlState.Normal)
|
||||
case .Low:
|
||||
sender.setTitle("Low", forState: UIControlState.Normal)
|
||||
case .Medium:
|
||||
sender.setTitle("Medium", forState: UIControlState.Normal)
|
||||
case .high:
|
||||
sender.setTitle("High", for: UIControlState())
|
||||
case .low:
|
||||
sender.setTitle("Low", for: UIControlState())
|
||||
case .medium:
|
||||
sender.setTitle("Medium", for: UIControlState())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue