24

I have a view controller that needs to be able to choose a picture from the photo album and also from the camera. I can only have 1 delegate method for didFinishPickingMediaWithInfo and while I can tell if it's an image, I can't seem to tell if it's from the album or from the camera (and I need to save it in the album first). Is there anything in the info that can help me distinguish from the two?

Thanks...

pizzafilms
  • 3,829
  • 4
  • 24
  • 39

2 Answers2

52

Because the UIImagePickerController is passed to the method, all you have to do is:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
    // Do something with an image from the camera
  } else {
    // Do something with an image from another source
  }
}
SahilS
  • 396
  • 5
  • 7
camdez
  • 1,614
  • 1
  • 18
  • 18
11

In Swift3:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

    if picker.sourceType == .camera {
      // Do something with an image from the camera
    }
    else {
      // Do something with an image from another source
    }

  }
Fattie
  • 27,874
  • 70
  • 431
  • 719
Allan Scofield
  • 1,884
  • 18
  • 14
  • 1
    In Swift 3.0, it's now `picker.sourceType == .camera`, since `.Camera` has been replaced by `.camera`. The other values are `.photoLibrary` and `.savedPhotosAlbum`. HTH – duthen Jan 24 '17 at 09:34