0

I try to display a picture of the camera in a UIImageView.

I try to debug my application (whit @property (nonatomic,weak) IBOutlet UILabel *messageLabel; ),

-------Line "[output captureStillImageAsynchronouslyFromConnection ..."

I have the value assigned before the call. (self.messageLabel.text = @"before !!"; I never have the value @"Test !!")

the return of the variable result is "OK"

I use Entitlements: com.apple.security.device.camera

Can you help me debug more detail.

Here is my code

-(NSString*)  takePhoto
{
    AVCaptureDevice *frontalCamera;
    AVCaptureSession *photoSession;
    NSString* result;

    NSArray *allCameras = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for ( int i = 0; i < allCameras.count; i++ )
    {
        AVCaptureDevice *camera = [allCameras objectAtIndex:i];

        if ( camera.position == AVCaptureDevicePositionFront )
        {
            frontalCamera = camera;
        }
    }

    if ( frontalCamera != nil )
    {
        photoSession = [[AVCaptureSession alloc] init];

        NSError *error;
        AVCaptureDeviceInput *input =
        [AVCaptureDeviceInput deviceInputWithDevice:frontalCamera error:&error];
        if ( !error && [photoSession canAddInput:input] )
        {   
            [photoSession addInput:input];

            AVCaptureStillImageOutput *output = [[AVCaptureStillImageOutput alloc] init];

            [output setOutputSettings:
             [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil]];
            if ( [photoSession canAddOutput:output] )
            {
                [photoSession addOutput:output];

                AVCaptureConnection *videoConnection = nil;

                for (AVCaptureConnection *connection in output.connections)
                {
                    for (AVCaptureInputPort *port in [connection inputPorts])
                    {
                        if ([[port mediaType] isEqual:AVMediaTypeVideo] )
                        {
                            videoConnection = connection;
                            break;
                        }
                    }
                    if (videoConnection) { break; }
                }
                if ( videoConnection )
                {

                    [photoSession startRunning];
                    result = @"Let's Go ?";
                    self.messageLabel.text = @"before !!";
                    [output captureStillImageAsynchronouslyFromConnection:videoConnection
                                                        completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
                                                            self.messageLabel.text = @"Test !!";
                                                            if (imageDataSampleBuffer != NULL)
                                                            {
                                                                NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
                                                                UIImage *photo = [[UIImage alloc] initWithData:imageData];
                                                                self.vImage.image = photo;

                                                            }
                                                        }];
                    result = @"OK";
                }
            }
        }
    }
    return result;
}
Nicks777
  • 1
  • 1
  • It is a little unclear what you are asking. – Zach Spencer Jan 14 '15 at 20:25
  • The goal is to display a picture in a UIImageView, but that remains empty. My variable is messageLabel is a label that allows me to debug. messageLabel never value "Test !!" Did see another method to place a picture in a UIImageView? – Nicks777 Jan 14 '15 at 20:32
  • you don't handle the error you get back at all.. look at that as a first step – Daij-Djan Jan 15 '15 at 13:32
  • I did not understand what you mean Daij-Djan (can you give an example with my code or is missing?). Do you know why it is not showing in UIImageView? – Nicks777 Jan 18 '15 at 12:56
  • is your issue fixed? if not then assign image on main queue. – fibnochi Mar 06 '15 at 07:25

0 Answers0