Camera Feature: to touch screen to call the camera, and save image in photo lib
-
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
-
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) } }
-
run iPhone Simulator.
- Reason for Exception Error occured.