如何判断didFinishPickingMediaWithInfo返回的图像是来自相机还是photoalbum?

时间:2011-08-23 01:12:32

标签: uiimagepickercontroller

我有一个视图控制器,需要能够从相册和相机中选择一张图片。我只能为didFinishPickingMediaWithInfo提供一个委托方法,虽然我可以判断它是否是一个图像,我似乎无法判断它是来自相册还是来自相机(我需要先将它保存在相册中)。信息中有什么可以帮我区分这两个吗?

...谢谢

2 个答案:

答案 0 :(得分:51)

因为UIImagePickerController已传递给方法,所以您只需要:

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

答案 1 :(得分:9)

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

  }