0

I have implemented the following and camera is opened but app is crashed and sometime when open and take the pictures then app is crasshed and log only show "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 Received memory warning."

The same functionality I have used for take the image from gallery and its working.

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:      (NSInteger)buttonIndex{
  if (buttonIndex==0) {
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                              message:@"Device has no Camera!"
                                                             delegate:nil
                                                    cancelButtonTitle:@"OK"
                                                    otherButtonTitles: nil];

        [myAlertView show];

    }else{

        [self performSelector:@selector(loadCamera) withObject:nil afterDelay:1.0];

    }    
}
}


-(void)loadCamera{

picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
picker1.allowsEditing=YES;
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker1 animated:YES completion:NULL];
}   

Can anyone help.

Chandan Kumar Jha
  • 325
  • 2
  • 4
  • 18

3 Answers3

1

Solved it by following code:

-(void)loadCamera{
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])  
            {
            dispatch_async(dispatch_get_main_queue(), ^{

            picker1 = [[UIImagePickerController alloc] init];
            picker1.delegate = self;
            picker1.allowsEditing=YES;
            picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:picker1 animated:YES completion: nil];

         });
       }
   }

This code worked for me with iOS 9.2 and xCode 7.2

Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
  • Also in ios 12.1 this was a bug reported by appstore to my application. I added dispatch_async and it started working. thanks – Alp Altunel Nov 27 '18 at 07:20
0
- (IBAction)takeAPhoto:(VSButton *)sender {


    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                              message:@"Device has no camera"
                                                             delegate:nil
                                                    cancelButtonTitle:@"OK"
                                                    otherButtonTitles: nil];

        [myAlertView show];

    }else {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController:picker animated:YES completion:NULL];
    }

}
0
[self performSelector:@selector(loadCamera) withObject:nil afterDelay:1.0];
-(void)loadCamera

{
if ([UIIagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera)

{

picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
picker1.allowsEditing=YES;
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker1 animated:YES completion:NULL];

}

}
Sabby
  • 403
  • 3
  • 15
  • I used the above but app still crash and also use its delegates - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { – Chandan Kumar Jha Feb 25 '16 at 06:11