Iphone AVCamDemo:completionHandler代码未命中
我正在精简Iphone AVCamDemo:completionHandler代码未命中,iphone,avfoundation,image-capture,Iphone,Avfoundation,Image Capture,我正在精简AVCamDemo项目,这样我就可以尝试只捕获静态图像 下面是captureStillImage()方法的新代码: - (void) captureStillImage { AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]
AVCamDemo
项目,这样我就可以尝试只捕获静态图像
下面是captureStillImage()
方法的新代码:
- (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) {
NSLog(@"In the completionHandler block");
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self writeImageFile:image];
[image release];
}
if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
[[self delegate] captureManagerStillImageCaptured:self];
}
}];
NSLog(@"exiting....");
}
在我的测试中,我发现有时候,块中的NSLog语句没有执行…因此静态图像文件没有保存
我遇到时间问题了吗?如果是,我如何称呼他们
谢谢,并致以问候。
山姆