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 i开发者_如何学JAVAmage, 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...
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
}
}
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
}
}
精彩评论