7

When,I am capturing image from camera then it is giving error on console in ios7.I tried firstly without adding Thread.sleep(3000) in code but that was also not working.

complete error: 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.

code:

public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        // Perform any additional setup after loading the view, typically from a nib.           

        PictureFromCameraButton.TouchUpInside += PictureFromCameraButton_Click;

    }

private void PictureFromCameraButton_Click (object sender, EventArgs e)
    {
        try {
            Thread.Sleep (4000);                
                ImagePickerController.SetSourceType(UIImagePickerControllerSourceType.Camera);
    this.PresentViewController (ImagePickerController, true, null);


        } catch (NotSupportedException exception) {
            //Logging Exception in Flurry
            FA.Flurry.LogError(exception.GetType().Name,exception.Message,
                               new NSError(NSError.CocoaErrorDomain,3584));

            BeginInvokeOnMainThread (() => {
                UIAlertView ErrorAlert = new UIAlertView ("Device unsupported", "Your device does not support this feature",
                                                         new UIAlertViewDelegate (), "OK");
                ErrorAlert.Show ();
            });
        } catch (Exception ex) {
            //Logging Exception in Flurry
            FA.Flurry.LogError(ex.GetType().Name,ex.Message,
                               new NSError(NSError.CocoaErrorDomain,3584));
            this.ShowErrorInProcessingAlertView ();
        }
    }
Larry OBrien
  • 8,484
  • 1
  • 41
  • 75
Mahesh Bansode
  • 297
  • 1
  • 3
  • 13
  • Does http://stackoverflow.com/questions/18890003/uiimagepicker-get-error-snapshotting-a-view-that-has-not-been-rendered-results help you at all? – Larry OBrien Jan 20 '14 at 19:33
  • I had implemented above solution in Xamarin.ios and tested but sometimes it is not generating error and sometimes not.I have tested it lot more times. – Mahesh Bansode Feb 01 '14 at 13:24

3 Answers3

3

To fix this problem in iOS 7, this is what solved my same error.

When I present the UIImagePickerController which in my case is called imagePickerController

Do not use nil or NULL. Instead, I used the below code and the error no longer appears when opening the camera.

[self presentViewController:imagePickerController animated:YES completion:^{....}];
Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
0

This is a bit of a hack but sometimes you need something initialized at some time in the lifecycle for interaction reasons or whatever. So what I did is just dispatched it after 0.1 seconds on the view it sits in and it seemed to work okay. Looking more into this.

    double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
     // Show camera view controller.
[self presentViewController:imagePickerController animated:YES completion:nil];


});

Hope this helps till someone finds a much better solution.

Shawn
  • 667
  • 8
  • 19
-1

Snapshotting a view that has not been rendered results in an empty snapshot same error.

This is definitely a bug and you can find this in apple developer forums as well.

I have tried to avoid this error using lot of other answers on stack overflow but could not fix this issue. However using this I could some how not get this error, i would not call this a fix, But give it a try and let me know if it had fixed the issue. Dismiss the view controller using the Grand Central Dispatch async from the main queue fixed the issue for me.

-(void)imagePickerController:(UIImagePickerController *)picker     didFinishPickingMediaWithInfo:(NSDictionary *)info {

// Code to handle the image data 

dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];
});
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];

});

}