AVCaptureDeviceInput deviceInputWithDevice为某些用户

时间:2018-05-02 09:26:00

标签: ios objective-c iphone xcode

我正在使用设备的相机点击一些照片。以下代码适用于近90%的用户,但对于其余用户来说却崩溃了。

_session = [AVCaptureSession new];
_session.sessionPreset = AVCaptureSessionPresetPhoto;

//
// setup device
//

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

if ([device lockForConfiguration:nil]) {
    if (device.autoFocusRangeRestrictionSupported) {
        device.autoFocusRangeRestriction = AVCaptureAutoFocusRangeRestrictionNear;
    }

    if (device.smoothAutoFocusSupported) {
        device.smoothAutoFocusEnabled = YES;
    }

    if([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]){
        device.focusMode = AVCaptureFocusModeContinuousAutoFocus;
    }

    device.exposureMode = AVCaptureExposureModeContinuousAutoExposure;

    [device unlockForConfiguration];
}

//
// add device input to session
//

AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
[_session addInput:deviceInput];

从崩溃日志中可以看出[AVCaptureSession addInput:]无法添加一个零AVCaptureInput,这基本上意味着某些用户的deviceInput对象即将为零。任何人都可以帮助我解决这个问题的根本原因,或者在这种情况下这个对象可能是零,因为它对大多数用户来说都非常好。

0 个答案:

没有答案