Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - Snapshotting a view that has not been rendered results in an empty snapshot

Tags:

ios

swift

My var:

@IBOutlet weak var imageView: UIImageView!

Take photo function:

func takePhoto(){
        let picker = UIImagePickerController()

        picker.delegate = self
        picker.sourceType = .Camera

        presentViewController(picker, animated: true, completion: nil)
    }

Error message:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates

Any ideas?

like image 710
Eri-Sklii Avatar asked Aug 12 '15 01:08

Eri-Sklii


3 Answers

I have had the same problem - I have two options once I have called the VC - From Photos or Selfie - and when I select Selfie i.e. camera Xcode prints that message but not ion I select Photos - so my guess is its a bug in the camera app. It has never crashed my app so I ignore it Code:

@IBAction func openCameraButton(sender: AnyObject) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) == true {
        camera = true
        imagePicker.delegate = self
        imagePicker.sourceType = .Camera
        imagePicker.allowsEditing = false
        self.presentViewController(imagePicker, animated: true, completion: nil)
    }else{
        noCamera()

    }
}
like image 140
Jeremy Avatar answered Nov 05 '22 11:11

Jeremy


Make sure you have:

super.viewDidLoad()

in your viewDidLoad func.

like image 1
FlatDog Avatar answered Nov 05 '22 12:11

FlatDog


put your self.presentViewController or your self.navigationController?.showViewController inside dispatch_async(dispatch_get_main_queue()) {

dispatch_async(dispatch_get_main_queue()) {
  self.presentViewController(imagePicker, animated: true, completion: nil)
}   
like image 1
Deyson Avatar answered Nov 05 '22 12:11

Deyson