Skip to content

Instantly share code, notes, and snippets.

// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
import AVFoundation
let status = AVCaptureDevice.authorizationStatus(for: .video)
switch status {
case .authorized:
print("authorized")
case .notDetermined:
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
import AVFoundation
AVCaptureDevice.requestAccess(for: .video, completionHandler: { granted in
if granted {
print("granted")
} else {
print("unauthorized")
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
import Foundation
import AVFoundation
enum CameraAuthorizationStatus {
case notRequested
case granted
case unauthorized
// 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/
import UIKit
protocol RequestCameraAuthorizationViewDelegate: class {
func requestCameraAuthorizationActionButtonTapped()
}
class RequestCameraAuthorizationView: UIView {
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
@IBOutlet private weak var cameraImageView: UIImageView!
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var messageLabel: UILabel!
@IBOutlet private weak var actionButton: UIButton!
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
import UIKit
class RequestCameraAuthorizationView: UIView {
@IBOutlet private weak var contentView: UIView!
override init(frame: CGRect) {
@hashaam
hashaam / background-color-of-view-in-viewcontroller.swift
Last active August 16, 2020 16:56
Change background color of view in view controller
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
}
@hashaam
hashaam / specify-root-view-controller-of-uiwindow-in-scenedelegate.swift
Last active August 16, 2020 16:56
Specify root view controller of UIWindow in SceneDelegate
// Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
// Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
let nibName = String(describing: LaunchViewController.self)
let bundle = Bundle.main
let launchViewController = LaunchViewController(nibName: nibName, bundle: bundle)
window?.rootViewController = launchViewController
@hashaam
hashaam / google-screenshot-firebase-cloud-function.ts
Created January 16, 2019 05:52
This firebase cloud function takes screenshot of google home page and saves in firebase storage bucket under screenshots/google.png, every time it is run.
import * as functions from 'firebase-functions';
import * as admin from "firebase-admin";
import * as puppeteer from "puppeteer";
admin.initializeApp()
export const takeGoogleScreenshot = functions
.runWith({ memory: "1GB" })
.https.onRequest(async (request, response) => {
const browser = await puppeteer.launch({