Pergunta

Hey I'm new to iPhone and I have been trying to make an gallery kind of app using ARC. where i am capturing image from camera using UIImagePickerController. Sometimes when i am clicking on camera button..then it is working fine but sometimes it is displaying the preview screen like below screenshot, then user have to tap on UIImagePicker preview cancel button and again click on camera button for capturing image successfully..Can anyone tell me the reason why i am getting this problem?

enter image description here

here is my code :

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

Thank you for your help.

Foi útil?

Solução

Your code looks fine, but I know that the UIImagePicker is resource consuming.

I think it is more optimized to do the instantiation only once. Put this in your viewWillAppear method:

self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
self.imagePickerController.allowsEditing = YES;
self.imagePickerController.sourceType = sourceType;

Then when you want to present it use:

[self presentViewController:self.imagePickerController animated:YES completion:nil];

I noticed that it is way faster to present it this way. Let me know if it solved your issue.

Outras dicas

For Camera user these

 _imgPickerController = [[UIImagePickerController alloc]init];
[_imgPickerController setDelegate:self];
[_imgPickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
 _imgPickerController.showsCameraControls = YES;
[self presentViewController:_imgPickerController animated:NO completion:Nil];

Don't forget to import these two Delegates

UIImagePickerControllerDelegate and UINavigationControllerDelegate
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top