2014-02-17 40 views
0

我正在使用AV Foundation框架。我正在嘗試爲「AVCaptureDeviceInput」對象執行「deviceInputWithDevice」的方法調用。嘗試執行方法調用時使用未聲明的標識符錯誤

的問題是,該方法調用包含了我有一個名爲「錯誤」的「錯誤」參數,我不斷收到在Xcode這樣的警告:使用undelcared標識「錯誤」

我所有的AV基金代碼位於View Controller的ViewDidLoad方法實現中。這是它:

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

    session.sessionPreset = AVCaptureSessionPresetHigh; 

    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 

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

    [session addInput:input]; 

我不明白爲什麼它不斷給我的「錯誤」參數未聲明的標識符警告。

任何幫助,非常感謝。

回答

2

您必須聲明error變量,你要使用:

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

並注意當您將它傳遞給方法的&error需要。當然你應該檢查它:

if (input) { 
    // it succeeded, do something 
} else { 
    NSLog(@"Error trying to call deviceInputWithDevice: %@", error); 
} 
+0

謝謝你的幫助。它工作完美。 – user3117509

相關問題