Pregunta

I am using the AV Foundation framework. I am trying to perform a method call of "deviceInputWithDevice" for an "AVCaptureDeviceInput" object.

The problem is that the method call contains an "error" parameter that I have named "error" and I keep getting this warning in xcode: Use of undelcared identifier 'error'

All of my AV Foundation code is located in the View Controller's ViewDidLoad method implementation. Here it is:

    AVCaptureSession *session = [[AVCaptureSession alloc]init];

    session.sessionPreset = AVCaptureSessionPresetHigh;

    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:error];

    [session addInput:input];

I can't figure out why it keeps giving me the undeclared identifier warning for the "error" parameter.

Any help is greatly appreciated.

¿Fue útil?

Solución

You have to declare the error variable that you are trying to use:

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];

And note that you need an & before error when you pass it to the method. And of course you should check it:

if (input) {
    // it succeeded, do something
} else {
    NSLog(@"Error trying to call deviceInputWithDevice: %@", error);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top