Skip to content

Instantly share code, notes, and snippets.

@hashaam
hashaam / turn-on-off-video-camera-torch.swift
Created August 24, 2022 16:51
Turn On/Off Video Camera Torch
/*
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
@hashaam
hashaam / capture-microphone-sound.swift
Created August 1, 2022 20:52
Capture Microphone Sound
/*
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 20:54
Request Camera Authorization - Snippet 2
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 20:33
Request Camera Authorization - Snippet 1
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()
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
class RequestCameraAuthorizationView: UIView {
// ...
private func customInit() {
// ...
setupActionButtonShadow()
}
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)
// 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()
// 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()
}
}
// 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