Ios 苹果源代码-require(error==nil,bail)导致错误

Ios 苹果源代码-require(error==nil,bail)导致错误,ios,compiler-errors,automatic-ref-counting,Ios,Compiler Errors,Automatic Ref Counting,我试图使用一些苹果的,但代码中充斥着以下语句: require( error == nil, bail ); 在ARC项目中使用时,会导致各种错误转到受保护的范围 我如何处理此代码 以下是一个例子: - (void)setupAVCapture { NSError *error = nil; AVCaptureSession *session = [AVCaptureSession new]; if ([[UIDevice currentDevice] userInt

我试图使用一些苹果的,但代码中充斥着以下语句:

require( error == nil, bail );
在ARC项目中使用时,会导致各种错误转到受保护的范围

我如何处理此代码

以下是一个例子:

- (void)setupAVCapture
{
    NSError *error = nil;

    AVCaptureSession *session = [AVCaptureSession new];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
        [session setSessionPreset:AVCaptureSessionPreset640x480];
    else
        [session setSessionPreset:AVCaptureSessionPresetPhoto];

    // Select a video device, make an input
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];


    require( error == nil, bail ); //ERROR: "Goto into protected scope"

    isUsingFrontFacingCamera = NO;
    if ( [session canAddInput:deviceInput] )
        [session addInput:deviceInput];

    // Make a still image output
    self.stillImageOutput = [AVCaptureStillImageOutput new];
    [self.stillImageOutput addObserver:self forKeyPath:@"capturingStillImage" options:NSKeyValueObservingOptionNew context:(__bridge void *)(AVCaptureStillImageIsCapturingStillImageContext)];
    if ( [session canAddOutput:self.stillImageOutput] )
        [session addOutput:self.stillImageOutput];

    // Make a video data output
    self.videoDataOutput = [AVCaptureVideoDataOutput new];

    // we want BGRA, both CoreGraphics and OpenGL work well with 'BGRA'
    NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
                                       [NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
    [self.videoDataOutput setVideoSettings:rgbOutputSettings];
    [self.videoDataOutput setAlwaysDiscardsLateVideoFrames:YES]; // discard if the data output queue is blocked (as we process the still image)

    // create a serial dispatch queue used for the sample buffer delegate as well as when a still image is captured
    // a serial dispatch queue must be used to guarantee that video frames will be delivered in order
    // see the header doc for setSampleBufferDelegate:queue: for more information
    videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);
    [self.videoDataOutput setSampleBufferDelegate:self queue:videoDataOutputQueue];

    if ( [session canAddOutput:self.videoDataOutput] )
        [session addOutput:self.videoDataOutput];
    [[self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:NO];

    effectiveScale = 1.0;
    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    [self.previewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
    [self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
    CALayer *rootLayer = [self.previewView layer];
    [rootLayer setMasksToBounds:YES];
    [self.previewLayer setFrame:[rootLayer bounds]];
    [rootLayer addSublayer:self.previewLayer];
    [session startRunning];

bail:
    session = nil;
    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Failed with error %d", (int)[error code]]
                                                            message:[error localizedDescription]
                                                           delegate:nil
                                                  cancelButtonTitle:@"Dismiss"
                                                  otherButtonTitles:nil];
        [alertView show];
        [self teardownAVCapture];
    }

}

添加大括号和大括号以提及范围

require( error == nil, bail );
{

}
bail:
{

}
例如:


添加大括号和大括号以提及范围

require( error == nil, bail );
{

}
bail:
{

}
例如:


或者干脆关闭这些文件的ARC?@H2CO3我不能单独使用这些文件。我必须将部分内容复制并粘贴到我自己的代码中。如果你想使用require调用,那么你需要导入相应的标题:import。或者干脆关闭这些文件的ARC?@H2CO3我不能单独使用这些文件。我必须将部分复制并粘贴到我自己的代码中。如果你想使用require调用,那么你需要导入适当的标题:import。这并不总是有效的。显然,bail在一个包含一个或多个块变量的范围内;这是不允许的。更多信息,请参阅。这里提出的解决方案是通过将_块变量放在大括号分隔的块中来限制_块变量的范围。这可能并不总是有效的;这并不总是有效的。显然,bail在一个包含一个或多个块变量的范围内;这是不允许的。更多信息,请参阅。这里提出的解决方案是通过将_块变量放在大括号分隔的块中来限制_块变量的范围。这可能并不总是有效的;