UIImagePicker在ios7 / iphone 4s上崩溃了

时间:2013-10-16 06:12:57

标签: iphone ios objective-c ios7

我有一个使用UIImagePickerController的应用程序,允许用户拍照。

我已将测试用例缩减为单个视图控制器应用程序中最简单的序列。这是我的代码。

//
//  CTViewController.h
//  Camera Test
//

#import <UIKit/UIKit.h>

@interface CTViewController : UIViewController <UINavigationControllerDelegate,   UIImagePickerControllerDelegate>

@property (nonatomic, retain) UIImagePickerController *cameraController;

- (IBAction)takePicture:(id)sender;

@end

代码正文如下:

//
//  CTViewController.m
//  Camera Test

#import "CTViewController.h"

....

- (void)didReceiveMemoryWarning
{
    NSLog(@"%s", __func__);

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)takePicture:(id)sender
{
    self.cameraController = [[UIImagePickerController alloc] init];

    self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.cameraController.allowsEditing = YES;
    self.cameraController.delegate = self;
    [self presentViewController:self.cameraController animated:YES completion:nil];
}

'takePicture'连接到我可以在屏幕中间按下的按钮。

在ios 6上,一切都运行良好,但是在ios 7上,一旦显示了viewcontroller,我就会得到一连串的内存警告。因此:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Received memory warning.
-[CTViewController didReceiveMemoryWarning]

.... <here I take a picture, which I do nothing with>

Received memory warning.
-[CTViewController didReceiveMemoryWarning]
Received memory warning.
-[CTViewController didReceiveMemoryWarning]

.... <I get a cascade of these warnings>

该应用程序是使用ios 7.0 sdk使用xcode 5构建的。如果我使用ios 6.1 sdk构建,但在ios7上运行,则会出现同样的问题。使用ios 6.1 sdk构建并在ios 6.1.3上运行不会导致任何消息,也不会产生任何问题。

我的完整应用程序在ios 7上有50%的时间崩溃。我通过抛出大量内容(图像大部分)来回应内存警告并且分析确认了这一点,但我仍然得到级联警告(即在释放内存后它们会继续运行。)

如果我使用前置摄像头,从图库中选择或使用iPad 3,则没有消息。因此,我怀疑使用后置摄像头时内存问题与UIImagePickerController的大小有关。

我已经完全探索了stackoverflow,并特别关注这篇文章 - UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

我已尝试过所有建议,但我的简单测试应用程序排除了大部分解释。

有什么想法?我应该放弃对iPhone 4S的支持吗?我还没有在iPhone 5上确认问题,但我会尽快更新这个问题。

: - )

1 个答案:

答案 0 :(得分:3)

我建议您不要为图像选择器使用属性,而是使用本地对象。请参阅下面我的代码,该代码在IOS7上也能正常工作。

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.showsCameraControls = YES;

    [self presentViewController:imagePicker animated:YES completion:nil];
}