简体   繁体   English

canSetSessionPreset:AVCaptureSessionPreset1920x1080在iOS4中导致“访问错误”

[英]canSetSessionPreset:AVCaptureSessionPreset1920x1080 causes 'Bad Access' in iOS4

Here is my code: 这是我的代码:

if( [self.captureSession canSetSessionPreset:AVCaptureSessionPreset1920x1080] == YES )
    {
    [self.captureSession setSessionPreset:AVCaptureSessionPreset1920x1080];
    self.currentPreset = GMCVideoCaptureRecordingPresetFullHD;
    }

On iOS4 execution stops on the first line with 'Bad access' error. 在iOS4上,执行在第一行停止,并显示“错误访问”错误。 On iOS5 it works fine. 在iOS5上运行正常。

How to correctly check for compatibility here? 如何在此处正确检查兼容性?

AVCaptureSessionPreset1920x1080 is an NSString *const . AVCaptureSessionPreset1920x1080NSString *const You can just check that its address is not NULL . 您只需检查其地址是否为NULL So like so: 像这样:

if( &AVCaptureSessionPreset1920x1080 != NULL && [self.captureSession canSetSessionPreset:AVCaptureSessionPreset1920x1080] == YES )
{
    [self.captureSession setSessionPreset:AVCaptureSessionPreset1920x1080];
    self.currentPreset = GMCVideoCaptureRecordingPresetFullHD;
}

That should do what you want. 那应该做你想要的。 Note that you won't be setting the preset on < iOS 5 though so you will presumably want an else in there to handle the case of it being < iOS 5 or the 1920x1080 preset can't be set. 请注意,尽管您不会在<iOS 5上设置预设,所以您可能想在其中设置else来处理<iOS 5或无法设置1920x1080预设的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM