我正在尝试创建一个AVCaptureSession.我的代码基于WWDC 2011视频,编号419.
我有以下行与WWDC 2011视频中的代码完全相同,它也与此处的代码相同http://www.bardecode.com/en/knowledge-base/214-detailed-description-of-work -around换avcapturevideopreviewlayer-问题在-IOS-41.html
// Create a device input with the device and add it to the session.
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
error:&error];
Run Code Online (Sandbox Code Playgroud)
但Xcode表示&错误是使用未声明的标识符.
这是因为您没有定义NSError error变量,而是在提供使用时的地址&error.
如果你通过...定义变量
NSError *error = nil;
Run Code Online (Sandbox Code Playgroud)
...在线之前,一切都应该好.
作为一个解释,如果您查看AVCaptureDeviceInput deviceInputWithDevice:error:方法的签名,您将看到以下内容:
+ (id)deviceInputWithDevice:(AVCaptureDevice *)device error:(NSError **)outError
Run Code Online (Sandbox Code Playgroud)
换句话说,此方法需要提供NSError指针变量的地址作为ourError参数.