I'm trying to select an photo from device Gallery and set in UIImage but the device crash after user select the photo from library:
Here is the crash log:
Notice: Formulating crash report for process [7997]
Aug 8 10:16:36 iPad ReportCrash[8000] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Aug 8 10:16:36 iPad com.apple.launchd[1]
(UIKitApplication:[0x8dd8][7997]) <Warning>:
(UIKitApplication:[0x8dd8]) Job appears to have
crashed: Trace/BPT trap: 5
Aug 8 10:16:36 iPad backboardd[26] <Warning>: Application
'UIKitApplication:[0x8dd8]' exited abnormally with signal 5: Trace/BPT
trap: 5
and here is my code:
-(IBAction)btnSelecionarFotoClick:(id)sender {
if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
inserindoFoto = YES;
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
[picker release];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo {
NSData *dataObj = nil;
if (image) {
dataObj = UIImageJPEGRepresentation(image, 1.0);
}
if (imgUsuario.image) {
imgUsuario.image = nil;
[imgUsuario.image release];
}
imgUsuario.contentMode = UIViewContentModeScaleAspectFill;
imgUsuario.image = image;
[imgUsuario.layer setCornerRadius:5];
imgUsuario.layer.masksToBounds = YES;
[self dismissViewControllerAnimated:NO completion:nil];
inserindoFoto = NO;
}
EDIT
if I cancel without select the picture, crash too:
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[self dismissViewControllerAnimated:NO completion:nil];
}
I found the problem:
If I disable autoLayout works...but I need to use autoLayout
The Apple Documentation states that if you're using the
UIImagePickerControllerSourceTypePhotoLibraryfor the iPad, you must use a popover controller. You are modally presenting it full screen, which is probably why you are running into issues.UIImagePickerController Reference