Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:27:27+00:00 2026-06-11T10:27:27+00:00

I created a ‘mirror’-like view in my app that uses the front camera to

  • 0

I created a ‘mirror’-like view in my app that uses the front camera to show a ‘mirror’ to the user. The problem I’m having is that I have not touched this code in weeks (and it did work then) but now I’m testing it again and it’s not working. The code is the same as before, there are no errors coming up, and the view in the storyboard is exactly the same as before. I have no idea what is going on, so I was hoping that this website would help.

Here is my code:

if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
        //If the front camera is available, show the camera


        AVCaptureSession *session = [[AVCaptureSession alloc] init];
        AVCaptureOutput *output = [[AVCaptureStillImageOutput alloc] init];
        [session addOutput:output];

        //Setup camera input
        NSArray *possibleDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
        //You could check for front or back camera here, but for simplicity just grab the first device
        AVCaptureDevice *device = [possibleDevices objectAtIndex:1];
        NSError *error = nil;
        // create an input and add it to the session
        AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; //Handle errors

        //set the session preset
        session.sessionPreset = AVCaptureSessionPresetHigh; //Or other preset supported by the input device
        [session addInput:input];

        AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
        //Now you can add this layer to a view of your view controller
        [cameraView.layer addSublayer:previewLayer];
        previewLayer.frame = self.cameraView.bounds;
        [session startRunning];
        if ([session isRunning]) {
            NSLog(@"The session is running");
        }
        if ([session isInterrupted]) {
            NSLog(@"The session has been interupted");
        }

    } else {
        //Tell the user they don't have a front facing camera
    }

Thank You in advanced.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:27:29+00:00Added an answer on June 11, 2026 at 10:27 am

    Not sure if this is the problem but there is an inconsistency between your code and the comments. The inconsistency is with the following line of code:

    AVCaptureDevice *device = [possibleDevices objectAtIndex:1];
    

    In the comment above it says: “…for simplicity just grab the first device”. However, the code is grabbing the second device, NSArray is indexed from 0. I believe the comment should be corrected as I think you are assuming the front camera will be the second device in the array.

    If you are working on the assumption that the first device is the back camera and the second device is the front camera then this is a dangerous assumption. It would be much safer and more future proof to check the list of possibleDevices for the device that is the front camera.

    The following code will enumerate the list of possibleDevices and create input using the front camera.

    // Find the front camera and create an input and add it to the session
    AVCaptureDeviceInput* input = nil;
    
    for(AVCaptureDevice *device in possibleDevices) {
        if ([device position] == AVCaptureDevicePositionFront) {
            NSError *error = nil;
    
            input = [AVCaptureDeviceInput deviceInputWithDevice:device 
                                                          error:&error]; //Handle errors
            break;
        }
    }
    

    Update: I have just cut and pasted the code exactly as it is in the question into a simple project and it is working fine for me. I am seeing the video from the front camera. You should probably look elsewhere for the issue. First, I would be inclined to check the cameraView and associated layers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Created a WCF service that is being called by a Silverlight app. Both reside
Having created my first iOS app as part of my MSc project I now
Created a AlertDialog that is used to prompting the user to enter a keyword.
Created application is working toooo slow, looks like there are a lot of memory
created a singleview application with storyboard. Added three viewcontrollers apart from the one view
Created a google map with GMap2 and put pinpoints on there that open up
Created using Sphinx 0.6.5. I know Python's documentation uses reStructuredText , but it has
Created a custom validation attribute and I would like to get it to work
created a new IIS7 web site with Intergrated .net 4.0 app pool. URLs ending
Created an empty project in Xcode, which merely sets up the App Delegate with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.