I am trying to make a simple camera app. But when I execute the code with iOS simulator, the iphoe show only black image and appear anything.
I made it with the code below and two permissions which are Privacy - Camera Usage Description and Privacy - Photo Library Additions Usage Description.
I need some help for solving this.
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imageView: UIImageView!
@IBAction func launchCamera(_ sender: UIBarButtonItem) {
let camera = UIImagePickerController.SourceType.camera
if UIImagePickerController.isSourceTypeAvailable(camera){
let picker = UIImagePickerController()
picker.sourceType = camera
picker.delegate = self
self.present(picker, animated: true)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
self.imageView.image = image
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
self.dismiss(animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}