Skip to content

Instantly share code, notes, and snippets.

View turn-on-off-video-camera-torch.swift
/*
Step 1 - Privacy Text for Requesting Camera Permission
Open the Info.plist file as source code and enter the following text in the <dict></dict>:
<key>NSCameraUsageDescription</key>
<string>This app requires camera</string>
*/
// Step 2 - Imports
View capture-microphone-sound.swift
/*
Step 1 - Privacy Text for Requesting Microphone Permission
Open the Info.plist file as source code and enter the following text in the <dict></dict>:
<key>NSMicrophoneUsageDescription</key>
<string>This app requires microphone</string>
*/
/*
@hashaam
hashaam / request-camera-authorization-s2.swift
Created May 7, 2022
Request Camera Authorization - Snippet 2
View request-camera-authorization-s2.swift
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let authorizationStatus = getCameraAuthorization()
switch authorizationStatus {
@hashaam
hashaam / request-camera-authorization-s1.swift
Created May 7, 2022
Request Camera Authorization - Snippet 1
View request-camera-authorization-s1.swift
import UIKit
import AVFoundation // 1: Import AVFoundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 3: Get Camera Authorization and print the result
let authorizationStatus = getCameraAuthorization()
View request-camera-authorization-animation-methods.swift
private extension RequestCameraAuthorizationView {
// ...
func animateInView(view: UIView, delay: TimeInterval) {
view.alpha = 0
view.transform = CGAffineTransform(translationX: 0, y: -20)
let animation = UIViewPropertyAnimator(duration: 0.2, curve: .easeInOut) {
view.alpha = 1
view.transform = .identity
View request-camera-authorization-add-shadow-method-call.swift
class RequestCameraAuthorizationView: UIView {
// ...
private func customInit() {
// ...
setupActionButtonShadow()
}
View request-camera-authorization-add-shadow.swift
private extension RequestCameraAuthorizationView {
// ...
func setupActionButtonShadow() {
actionButton.layer.shadowColor = UIColor.black.cgColor
actionButton.layer.shadowRadius = 10
actionButton.layer.shadowOpacity = 0.3
actionButton.layer.masksToBounds = false
actionButton.layer.shadowOffset = CGSize(width: 5, height: 10)
View launch-view-controller-after-camera-authorization.swift
// 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()
View replace-action-button-method.swift
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
extension LaunchViewController: RequestCameraAuthorizationViewDelegate {
func requestCameraAuthorizationActionButtonTapped() {
requestCameraAuthorization()
}
}
View request-camera-authorization-method-in-launch-view-controller.swift
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
func requestCameraAuthorization() {
RequestCameraAuthorizationController.requestCameraAuthorization(completionHandler: { status in
switch status {
case .granted:
print("granted")
case .notRequested:
break