在iOS 8中,我有从相机捕捉图像的问题,直到现在我正在使用这段代码

UIImagePickerController *controller=[[UIImagePickerController alloc] init];
controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
controller.delegate=(id)self;
controller.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:controller animated:YES completion:nil];

但在iOS 8中,我得到了这个:

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.

我已经尝试了本文提供的解决方案

@property (strong,nonatomic)UIImagePickerController *controller;

_controller=[[UIImagePickerController alloc] init];
_controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
_controller.delegate=(id)self;
_controller.sourceType=UIImagePickerControllerSourceTypeCamera;
_[self presentViewController:controller animated:YES completion:nil];

...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...

double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self presentViewController:controller animated:YES completion:nil];
});

[self presentViewController:controller animated:YES completion:NULL];

[self presentViewController:controller animated:YES completion:^{

}];

任何想法?


当前回答

如果我们使用UIImagePickerController作为属性,那么这个警告将会消失。xcode假设我们没有使用UIImagePickerController的结果,如果我们在一个函数中实例化UIImagePickerController。

其他回答

我也遇到了同样的问题,我通过检查相机是否可用来解决它:

BOOL cameraAvailableFlag = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    if (cameraAvailableFlag)
        [self performSelector:@selector(showcamera) withObject:nil afterDelay:0.3];

我得到了同样的错误,在控制台怒吼的消息,同时打开相机。

’对一个没有被渲染的视图进行快照会导致一个空快照。确保你的视图在快照之前或屏幕更新后至少渲染过一次。”

对我来说,问题是在信息中的捆绑显示名称。plist文件。它是空的某种方式,我把我的应用程序名称在那里,现在它工作正常。我没有收到任何相机权限警报,因为空的Bundle显示名称。它阻止了视图的呈现。

问题不在于视图,而在于未经许可而呈现视图。你可以检查设置>隐私>相机,如果你的应用程序没有列出,问题可能是一样的。

我使用Phonegap,但这个线程一直作为第一个当谷歌关于错误消息。

对我来说,通过将imagetype定义为PNG,这个问题就消失了。

encodingType : Camera.EncodingType.PNG

所以整条线是:

 navigator.camera.getPicture(successFunction, failFunction, { encodingType : Camera.EncodingType.PNG, correctOrientation:true, sourceType : Camera.PictureSourceType    .PHOTOLIBRARY, quality: 70, allowEdit : false , destinationType: Camera.DestinationType.DATA_URL});

你的里程可能会有所不同,但这对我来说很管用。

我很确定这只是iOS 8.0的一个bug。这是最简单的POC应用程序的可复制性,它只是尝试呈现一个UIImagePickerController,就像你上面做的那样。此外,据我所知,没有其他模式可以显示图像拾取器/相机。你甚至可以下载苹果的Using UIImagePickerController示例应用程序,运行它,它会立即生成相同的错误。

也就是说,功能对我来说仍然有效。除了警告/错误,你的应用程序的功能有问题吗?

我已经尝试了一切,我的问题是,相机和图片库的图像选择器在它们显示后立即消失。我用下面这行(swift)解决了它

imagePicker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext