EyeQ Tech
EyeQ Tech

Reputation: 7358

Swift, Camera image doesn't return

Pardon me for beginner's question. I load up the camera and take photo, but it seems the override function imagePickerController is never called, so I can never set the photo to the imageView, code like below. Any idea? Thanks

@IBAction func takePhotoClick(_ sender: AnyObject) {
    imagePicker =  UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .camera

    present(imagePicker, animated: true, completion: nil)

}    
var imagePicker: UIImagePickerController!

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        imagePicker.dismiss(animated: true, completion: nil)

        photoImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage




}

Upvotes: 1

Views: 825

Answers (1)

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

You need to ask the use permission before access the user private data like contact number, photos , location , calendar , etc. in iOS 10 Apple is extending the scope of privacy control. You have to declare in Info.plist file access of any private data.

Which framework have privacy key in Info.plist :

Calendar , Contact , Reminder , Photo , Bluetooth Sharing , Microphone , Camera , Location , Heath , HomeKit , Media Library , Motion , CallKit , Speech Recognition , SiriKit , TV Provider.

for more information see this

check once are you added the following information in your plist

enter image description here

and then call the delegate method like

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage  {
    photoImageView.image = image
}

picker.dismiss(animated: true, completion: nil);
}

Upvotes: 2

Related Questions