У меня есть этот код в AVCamCaptureManager:
- (void) captureStillImage
{
AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([stillImageConnection isVideoOrientationSupported])
[stillImageConnection setVideoOrientation:orientation];
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
if (error) {
if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
[[self delegate] captureManager:self didFailWithError:error];
}
}
};
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
//ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
//UIImage *imagePhoto = [[UIImage alloc] initWithData:imageData];
/*
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:completionBlock];*/
self.image = [[UIImage alloc] initWithData:imageData];
//[imagePhoto release];
//[library release];
}
else
completionBlock(nil, error);
if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
[[self delegate] captureManagerStillImageCaptured:self];
}
}];
}
и этот метод в другом классе
- (IBAction)captureStillImage:(id)sender
{
// Capture a still image
//[[self stillButton] setEnabled:NO];
[[self captureManager] captureStillImage];
if ([captureManager image] == nil) NSLog(@"image nil");
[preview setImage:[captureManager image]];
[snap setAlpha:0.00];
[use setAlpha:1.00];
[retake setAlpha:1.00];
Моя проблема в том, что когда я вызываю IBAction, у меня когда-либо будет image = nil, потому что у меня есть другой метод в AsynchronouslyFromConnection; что я могу сделать, чтобы решить эту ситуацию?