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
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)
.
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;
-(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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.