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

旧街凉风 提交于 2019-12-04 09:59:01

问题


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


回答1:


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



回答2:


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
    }

  }


来源:https://stackoverflow.com/questions/7155311/how-can-i-tell-if-the-image-returned-from-didfinishpickingmediawithinfo-was-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!