Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if the image returned from didFinishPickingMediaWithInfo was from the camera or the photoalbum?

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...

like image 962
pizzafilms Avatar asked Aug 23 '11 01:08

pizzafilms


2 Answers

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
  }
}
like image 151
camdez Avatar answered Jun 03 '23 03:06

camdez


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
    }

  }
like image 31
Allan Scofield Avatar answered Jun 03 '23 02:06

Allan Scofield