Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Does anyone know about the NSCameraUsageDescription key with a string value explaining to user how app uses this data???

I am trying to code for an app to access the iPhone camera, all code is successful when building but when running on device, it crashes due to trying to access data without usage description? Not sure how to code for this so if anyone knows it would be very much appreciated. Here is my code so far:

class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate { let imagePicker = UIImagePickerController() @IBOutlet weak var imageViewer: UIImageView!

override func viewDidAppear(_ animated: Bool) {

    if UIImagePickerController.isCameraDeviceAvailable( UIImagePickerControllerCameraDevice.front) {
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera
        present(imagePicker, animated: true, completion: nil)
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
    dismiss(animated: true, completion: nil)
    imageViewer.image = image
}

}

1 Answer

Garrett Votaw
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Garrett Votaw
iOS Development Techdegree Graduate 15,223 Points

Hey Alfie,

That usage description can be added in the info.plist file. When you go to that file you can hit the + button and then add the "Privacy - Camera Usage" key. Make sure to add a description so that your users know why you are requesting access

Happy Coding!