Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!