Instantly share code, notes, and snippets.
Last active
August 16, 2020 16:53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw | |
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/ | |
import UIKit | |
class LaunchViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupViews() | |
} | |
} | |
private extension LaunchViewController { | |
func setupViews() { | |
addRequestCameraAuthorizationView() | |
} | |
func addRequestCameraAuthorizationView() { | |
let requestCameraAuthorizationView = RequestCameraAuthorizationView() | |
requestCameraAuthorizationView.translatesAutoresizingMaskIntoConstraints = false | |
requestCameraAuthorizationView.delegate = self | |
view.addSubview(requestCameraAuthorizationView) | |
NSLayoutConstraint.activate([ | |
requestCameraAuthorizationView.leadingAnchor.constraint(equalTo: view.leadingAnchor), | |
requestCameraAuthorizationView.topAnchor.constraint(equalTo: view.topAnchor), | |
requestCameraAuthorizationView.trailingAnchor.constraint(equalTo: view.trailingAnchor), | |
requestCameraAuthorizationView.bottomAnchor.constraint(equalTo: view.bottomAnchor) | |
]) | |
} | |
func requestCameraAuthorization() { | |
RequestCameraAuthorizationController.requestCameraAuthorization(completionHandler: { status in | |
switch status { | |
case .granted: | |
print("granted") | |
case .notRequested: | |
break | |
case .unauthorized: | |
print("unauthorized") | |
} | |
}) | |
} | |
} | |
extension LaunchViewController: RequestCameraAuthorizationViewDelegate { | |
func requestCameraAuthorizationActionButtonTapped() { | |
requestCameraAuthorization() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment