Mar*_*uir 9 iphone objective-c ios 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
Run Code Online (Sandbox Code Playgroud)
代码的主体如下:
//
// 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];
}
Run Code Online (Sandbox Code Playgroud)
'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>
Run Code Online (Sandbox Code Playgroud)
该应用程序是使用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错误:在iOS 7中快照未渲染的视图会导致空快照
我已经尝试了所有建议,但我的简单测试应用程序排除了大多数解释.
有什么想法吗?我应该放弃对iPhone 4S的支持吗?我还没有确认iPhone 5上的问题,但我会尽快更新这个问题.
:-)
我建议您不要使用图像选择器的属性,而是使用本地对象。请参阅下面我的代码,该代码在 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];
}
Run Code Online (Sandbox Code Playgroud)