【发布时间】:2013-10-16 06:12:57
【问题描述】:
我有一个应用程序,它使用 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 上,一旦出现视图控制器,我就会收到一连串的内存警告。因此:
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>
该应用程序是使用 xcode 5 使用 ios 7.0 sdk 构建的。如果我使用 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 上的问题,但我会尽快更新这个问题。
:-)
【问题讨论】:
-
我们也遇到了同样的问题,即在装有 iOS7 的 iPhone 4s 上查看并接受照片后相机崩溃。
-
这很奇怪,所以我不提供它作为答案。我有完全相同的问题,但在 iPhone 5s 上。花 4 个小时倾倒堆栈溢出并四处询问。最后,我重新启动了我的 iPhone 5s 并且噗,没有更多的内存警告。他们可能会返回,但在使用问题应用程序拍照 2 小时后,仍然没有内存警告。奇怪!
-
这似乎“修复”了它。什么鬼……
-
这可能与 ios7 尝试拍摄您的应用的快照视图以便在控制面板中显示它有关
-
我花了半天时间调试它,Jim 的重启答案解决了它... Jim 请提交它作为答案!
标签: iphone ios objective-c ios7