Skip to content

QueenieCplusplus/iOS_Back_2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iOS_Back_2

Camera Feature: to touch screen to call the camera, and save image in photo lib

  1. add K/V to ask for users auhthorization to camera usage and usage of image saving.

      Privacy - Camera Usage Description
      Privacy - Photo Lib Add Usage Description
    

ref: https://medium.com/彼得潘的-swift-ios-app-開發問題解答集/ios-10存取使用者私密資料都要加上usage-description-a01715e56491

  1. code in ControllerView.

     //  ViewController.swift
     //  KatesCamera
     //
     //  Created by KatesAndroid on 2021/1/27.
     //
    
     import UIKit
    
     class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
    
         override func viewDidLoad() {
             super.viewDidLoad()
             // Do any additional setup after loading the view.
         }
    
         override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    
             let imgP = UIImagePickerController()
             imgP.sourceType = .camera
             imgP.delegate = self
             show(imgP, sender: self)
         }
    
         func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
             let img = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
    
             UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil)
             dismiss(animated: true, completion: nil)
         }
    
    
     }
    

    ref: https://stackoverflow.com/questions/41717115/how-to-make-uiimagepickercontroller-for-camera-and-photo-library-at-the-same-tim

  2. run iPhone Simulator.

  1. Reason for Exception Error occured.