当我在我的应用程序中打开相机时它工作正常,但当我在我的应用程序中导航并返回到相机视图并再次尝试在iPad中打开我的相机时,应用程序崩溃并给我“收到内存警告”。应用程序在iPhone中工作正常,这个问题只出现在iPad上。
我的项目没有ARC所以我将我的项目转换为ARC以期获得良好的结果,但仍然我的应用程序在导航后在相机上崩溃。 任何人都可以告诉我如何使用iPad相机减少内存空间,以便我的应用程序停止接收内存警告。
这是我的相机代码
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
imagePicker=[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = NO;
//imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:imagePicker animated:YES completion:nil];
}
这是我获取图片的地方
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[Array removeAllObjects];
[picker dismissViewControllerAnimated:YES completion:nil];
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[array addObject:image];
image=nil;
}
我也尝试将popOverview用于相机,但它也无效。
在我调用UIImagePickerController的viewController中,我使用了5个动画,之前我在viewWillAppear中调用动画,而app崩溃了所以我将动画调用改为ViewDidLoad并且相机开始工作但直到我导航到我的上一个视图然后再回来打开相机。
答案 0 :(得分:3)
我遇到同样的问题所以我喜欢这个。
将UIImagePickerController设置为静态,如下所示。
static UIImagePickerController *imagePicker;
当您在此删除中获得图像时。
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
@autoreleasepool {// to release memory
// Probelm is you image size.
// When you get this image it is vary large.
// And i hope you are creating multiple copy's of this image.
// when you get image in
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// In last set image as nil
image = nil;
}
}
希望这能解决你的问题..: - )
答案 1 :(得分:2)
尝试在没有动画的情况下运行您的应用程序然后尝试,如果它有效,那么您需要改进动画内存分配,因为动画需要大量内存。
答案 2 :(得分:0)
请尝试使用popover
下面的code.tryUIImagePickerController
if([UIImagePickerContrller isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
controller.allowsEditing = YES;
controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
controller.delegate = self;
UIPopoverController *popController = [[UIPopoverController alloc] initWithContentViewController:controller];
popController.popoverContentSize = CGSizeMake(350.0f, 500);
[popController presentPopoverFromRect: self.button.frame inView:self.button.superview
permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]
}