0

I know its not a good question to be ask but i am stuck. How can i detect when user pick image from library not from camera and this library image saved via front camera or back camera? Like

if (library image from front camera)
{
  // Do something here
}  
else {
 // Do something here
} 
Umair_UAS
  • 113
  • 1
  • 10

1 Answers1

0

Your code checks for available cameras on the device. What you need to do is read the metadata for the image after you have taken the picture, that will include info on the camera.

Use this solution to read the Exif data that comes with the image to find out which camera obtained it: Exif Data from Image

You can check the image EXIF data in the info dictionary UIImagePicker passes in it's callback.

- (IBAction) handleTakePhoto:(UIButton *)sender {

    UIImagePickerController* picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:nil];

}

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    __block NSDictionary* metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];

    dispatch_async(dispatch_get_main_queue(), ^{

        NSLog(@"%@", [metadata valueForKeyPath:@"{Exif}.LensModel"]);

        [picker dismissViewControllerAnimated:YES completion:nil];

    });

}

The above snippet outputs

iPhone 6 Plus back camera 4.15mm f/2.2

You would have to parse out the "front" or "back" parts of the string.

Relying on parsing something that is parsed out of a string raises some red flags -- there is probably a better and more stable way of doing it.

Community
  • 1
  • 1
Harshal Bhavsar
  • 1,598
  • 15
  • 35