0
votes

Hello everyone i am having a crash when trying to present camera modally. here is my code :

if (!imagePicker) { imagePicker = [[UIImagePickerController alloc]init]; }

[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];


[imagePicker setDelegate:self];

[self presentModalViewController:imagePicker animated:YES];

[imagePicker release];

I have been through all searches here, but commonly the crash happens only after you taken a picture in

imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)info

i am not getting any details just the app closes and i see the thread is paused.

Any idea what's wrong here. For info i am testing in ipod touch 3G and iPhone 3GS and it

3
Can you share the crash log? - aqua
In my debug navigator i see nothing except Thread paused and yeah i got memory warning 2 times :) - veereev
enable your zombie objects to have better crash log. - vishwa.deepak
If the application is really crashing you might find some logs at ~/Library/Logs/DiagnosticReports/ or ~/Library/Logs/CrashReporter/MobileDevice/<DEVICE_NAME>. The behavior you describe could simply be the application switching out which is why the thread pauses instead of crashes. - aqua
Make sure you set imagePicker to nil in the imagePickerController:didFinishPickingImage:editingInfo: method. Failing to do so is the likely cause of your problem. - rmaddy

3 Answers

1
votes

UIImagePickerController can be a pain. Try

imagePicker = [[[UIImagePickerController alloc]init] autorelease];

and remove the [imagePicker release];

Frankly I wouldn't trust that conditional assignment by simply testing if(!imagePicker).

0
votes

clear the imagePicker variable after you release it or it will still be non-null when you go to take the second picture and crash because its actually been released.

[imagePicker release];
imagePicker = nil;
-1
votes

-(void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated

and

- (void)dismissModalViewControllerAnimated:(BOOL)animated

are Deprecated in iOS 6.0 so instead these method use respectively

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

and

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion