Photos
The Photos module provides unified access to the system photo library and camera. It enables scripts to:
- Capture photos or record videos using the system camera
- Pick images, videos, or Live Photos from the photo library
- Retrieve the most recent photos
- Save images or videos to the Photos app
All APIs are built on top of native iOS frameworks such as Photos and PHPicker, and follow these principles:
- System-managed permissions
- Promise-based asynchronous APIs
- System-controlled UI presentation
- Secure and constrained access to media data
CaptureInfo
CaptureInfo describes the complete result of a capture operation (photo or video).
Properties
-
cropRectThe cropping rectangle applied during editing.nullif no cropping was performed. -
originalImageThe original image captured by the camera. -
editedImageThe edited image, if editing was enabled and applied. -
imagePathFile path to the captured image on disk. -
mediaMetadataMetadata associated with the captured media, such as EXIF data. -
mediaPathFile path to the captured video. -
mediaTypeThe UTType string describing the media type.
availableMediaTypes()
Returns the list of media UTTypes supported by the current device’s camera.
Common use cases include checking whether video capture is supported or dynamically adjusting capture options.
Returns null if the information is unavailable.
capture(options)
Presents the system camera interface to capture a photo or record a video.
Options
-
modeCapture mode"photo": capture a photo"video": record a video
-
mediaTypesAllowed media UTTypes. -
allowsEditingWhether the user can edit the captured media. -
cameraDeviceCamera to use. Defaults to"rear". -
cameraFlashModeFlash behavior. Defaults to"auto". -
videoMaximumDurationMaximum video duration in seconds. -
videoQualityVideo resolution and encoding quality.
Behavior Notes
- The UI is fully system-managed
- The Promise resolves only after the user finishes or cancels the operation
- Permission prompts are handled by the system
pick(options)
Presents the system photo picker to select media items from the photo library.
Options
-
modePicker layout styledefault: grid layoutcompact: linear layout
-
filterAPHPickerFilterthat restricts selectable asset types. -
limitMaximum number of selectable items. Defaults to1.
Return Value
Returns an array of PHPickerResult objects.
Each result must be explicitly resolved into a concrete media representation.
PHPickerFilter
PHPickerFilter defines which asset types can be selected in Photos.pick.
It is a non-instantiable class and can only be constructed via static methods.
Basic Filters
-
PHPickerFilter.images()Allows selection of standard images. -
PHPickerFilter.videos()Allows selection of videos. -
PHPickerFilter.livePhotos()Allows selection of Live Photos. -
PHPickerFilter.bursts()Burst photo sequences. -
PHPickerFilter.panoramas()Panorama photos. -
PHPickerFilter.screenshots()Screenshots. -
PHPickerFilter.screenRecordings()Screen recording videos. -
PHPickerFilter.depthEffectPhotos()Photos with depth effects (portrait photos). -
PHPickerFilter.cinematicVideos()Cinematic mode videos. -
PHPickerFilter.slomoVideos()Slow-motion videos. -
PHPickerFilter.timelapseVideos()Time-lapse videos.
Composite Filters
-
PHPickerFilter.all(filters)Matches assets that satisfy all provided filters Logical AND -
PHPickerFilter.any(filters)Matches assets that satisfy at least one filter Logical OR -
PHPickerFilter.not(filter)Excludes assets matching the specified filter Logical NOT
Example
PHPickerResult
Represents a single item returned from the photo picker.
itemProvider: ItemProvider
The item provider for the selected asset, which can be used to load the asset.
livePhoto()
Attempts to read the result as a Live Photo.
Resolves to null if the asset cannot be represented as a Live Photo.
uiImage()
Attempts to read the result as a UIImage object.
Resolves to null if the asset cannot be represented as an image.
imagePath()
If this result can be read as an image, this file will be copied to the app group's sandbox and returns a promise that resolves to the image path, otherwise returns null, or rejects with an error. You should delete the image file when you no longer need it.
Example
videoPath()
If this result can be read as a video, this file will be copied to the app group's sandbox and returns a promise that resolves to the video path, otherwise returns null, or rejects with an error. You should delete the video file when you no longer need it.
getLatestPhotos(count)
Retrieves the most recent photos from the photo library.
Notes
- Images only (no videos)
- Ordered from newest to oldest
- Returns
nullif access is unavailable
pickPhotos(count)
Legacy convenience API for selecting a fixed number of photos.
Returns an array of UIImage objects without file paths or metadata.
takePhoto()
Quick photo capture API.
- No advanced configuration
- Returns
nullif the user cancels
savePhoto(path, options)
Saves an image file from disk to the Photos app.
savePhoto(image, options)
Saves raw image data directly to the Photos app, avoiding temporary files.
saveVideo(path, options)
Saves a video file from disk to the Photos app.
saveVideo(video, options)
Saves raw video data directly to the Photos app.
Design Notes
- All APIs are asynchronous and permission-aware
- All UI is system-managed and not customizable
- Picker results are lazy and must be explicitly resolved
- Save APIs return only success status, not asset identifiers
