2013-10-16 57 views
9

我有一个应用程序,它使用UIImagePickerController来允许用户拍照。UIImagePicker崩溃在ios7/iphone 4s

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

// 
// 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,如果我建立一个与IOS 6.1的SDK,但ios7运行7.0 SDK使用Xcode的5同样的问题时建造的。使用ios 6.1 sdk构建并在ios 6.1.3上运行不会导致任何消息和问题。

我的完整应用程序在ios 7上崩溃了50%。我通过抛出大量内容(图像大多数)内存不足和分析来回应内存警告,但我仍然得到警告级联(即在内存释放后它们继续)。

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

我有充分的探讨和计算器都显得格外这个帖子 - UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

我已经试过各种建议,但我的简单测试应用程序阻止大多数的解释。

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

:-)

+0

在iOS7上查看并接受iPhone 4s上的照片后,我们也遇到了相机崩溃的相同问题。 –

+4

这很奇怪,所以我不提供它作为答案。我有完全相同的问题,但在iPhone 5s上。花费4个小时来解决堆栈溢出问题。最后,我重新启动了我的iPhone 5s,并且没有更多的内存警告。他们可能会回来,但与问题应用程序拍摄2小时后,仍然没有记忆警告。奇怪的! – JimVision

+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]; 
} 
+0

您可以扩展此建议吗?我有一个自定义覆盖的应用程序,我将imagePicker的ref传递到覆盖控制器,这样我可以在覆盖IBAction中调用takePhoto: ** [self。cameraPickerRef takePicture] ** –

+0

另外,当我切换相机设备时,我将自定义黑色子视图添加到self.imagePicker.view,以便转换更好一些。在这种方法中,我需要对imagePicker的引用来添加子视图并设置相机设备。 –

+0

通过这种方式,只要您拍摄照片就可以将其取消分配,但如果您需要强大的参考,则比较复杂。 –