Skip to content

UIImagePickerControllerMediaEvent ​

UIImagePickerControllerMediaEvent represents the user taking a photo in the system camera screen.

The pick event of UIImagePickerController is this class. It carries the photo taken, and the user's crop when allowsEditing is on.

It belongs to the @nacrejs/camera package; for installation, see UIImagePickerController.

Inheritance: Event → UIImagePickerControllerMediaEvent

Constructor ​

UIImagePickerControllerMediaEvent()

Creates a UIImagePickerControllerMediaEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.

Instance properties ​

Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.

PropertyDescription
originalImage read-onlyThe photo taken, uncropped
editedImage read-onlyThe photo after the user cropped it
cropRect read-onlyThe part of the original photo the user cropped to

These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.

Events that use this class ​

ObjectEvents
UIImagePickerControllerpick

It can't be canceled: cancelable is false, and preventDefault() has no effect. After it is fired, the camera screen is still on screen; close it in the listener.

Examples ​

js
const picker = new UIImagePickerController();
picker.addEventListener('pick', (e) => {
  console.log(e instanceof UIImagePickerControllerMediaEvent, e.editedImage);
  picker.dismissViewController({ animated: true });
});

Effect: after taking a photo, prints true null, then closes the camera screen. Not verified: the simulator can't take photos.

Corresponding iOS API ​

Three entries of the info dictionary of the delegate method imagePickerController:didFinishPickingMediaWithInfo: are the three fields of the event object.

ObjCJS
info[UIImagePickerControllerOriginalImage]event.originalImage
info[UIImagePickerControllerEditedImage]event.editedImage
info[UIImagePickerControllerCropRect]event.cropRect

See also ​