简体   繁体   English

UIImagePickerController在presentmodal上崩溃?

[英]UIImagePickerController crash on presentmodal?

Hello everyone i am having a crash when trying to present camera modally. 大家好,我尝试模态展示相机时遇到了崩溃。 here is my code : 这是我的代码:

if (!imagePicker) { imagePicker = [[UIImagePickerController alloc]init]; 如果(!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 imagePickerController:(UIImagePickerController *)pick didFinishPickingImage:(UIImage *)img编辑信息:(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 有关信息,我正在ipod touch 3G和iPhone 3GS中对其进行测试

UIImagePickerController can be a pain. UIImagePickerController可能很痛苦。 Try 尝试

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

and remove the [imagePicker release] ; 并删除[imagePicker release]

Frankly I wouldn't trust that conditional assignment by simply testing if(!imagePicker) . 坦白说,我不会仅仅通过测试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变量,否则当您拍摄第二张照片并因为它实际上已被释放而崩溃时,它将仍然为非空。

[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 在iOS 6.0中已弃用,因此这些方法分别使用

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

and

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM