Skip to content

PHPickerFilter ​

PHPickerFilter represents which kinds of items a photo picker shows, for example only images, only videos, or images without screenshots. Assign it to the filter of a PHPickerConfiguration.

The twelve predefined filters are read from the class. Three static methods combine them into new filters, and combinations can be nested.

You need to install @nacrejs/photos first. See PHPickerViewController for how, or see Core and capability packages.

Inheritance: NSObject → PHPickerFilter

Constructor ​

You can't create one with new. new PHPickerFilter() throws TypeError:

Illegal constructor: PHPickerFilter is created by the runtime, not by new

You get filters from the static properties and static methods below.

Static properties ​

All are read-only. Each one returns the same object on every read.

PropertyWhat it shows
PHPickerFilter.imagesFilterImages, including Live Photos
PHPickerFilter.videosFilterVideos
PHPickerFilter.livePhotosFilterLive Photos
PHPickerFilter.depthEffectPhotosFilterPhotos with a depth effect (taken in Portrait mode)
PHPickerFilter.burstsFilterBursts
PHPickerFilter.panoramasFilterPanoramas
PHPickerFilter.screenshotsFilterScreenshots
PHPickerFilter.screenRecordingsFilterScreen recordings
PHPickerFilter.cinematicVideosFilterVideos shot in Cinematic mode
PHPickerFilter.slomoVideosFilterSlow-motion videos
PHPickerFilter.timelapseVideosFilterTime-lapse videos
PHPickerFilter.spatialMediaFilterSpatial photos and spatial videos

Static methods ​

MethodResulting filter
PHPickerFilter.anyFilterMatchingSubfilters()Matches any one of them
PHPickerFilter.allFilterMatchingSubfilters()Matches every one of them
PHPickerFilter.notFilterOfSubfilter()Doesn't match this one

Instance methods ​

MethodDescription
isEqual()Whether two filters mean the same thing

Comparing two filters ​

Compare two filters with isEqual(), not ===:

  • The twelve predefined filters return the same object on every read, so === works for them.
  • Combined filters are new objects every time. If you build the same combination twice, === is false and isEqual() is true.
  • Reading the configuration's filter doesn't return the object you assigned: the system stores a copy.

Examples ​

js
const config = new PHPickerConfiguration();
// Images, but no screenshots
config.filter = PHPickerFilter.allFilterMatchingSubfilters([
  PHPickerFilter.imagesFilter,
  PHPickerFilter.notFilterOfSubfilter(PHPickerFilter.screenshotsFilter),
]);

Effect: A photo picker created with this configuration shows photos, but no screenshots and no videos. The on-screen effect is not verified in the simulator.

Corresponding iOS API ​

ObjCJS
PHPickerFilter.imagesFilterPHPickerFilter.imagesFilter
[PHPickerFilter anyFilterMatchingSubfilters:@[a, b]]PHPickerFilter.anyFilterMatchingSubfilters([a, b])
[PHPickerFilter allFilterMatchingSubfilters:@[a, b]]PHPickerFilter.allFilterMatchingSubfilters([a, b])
[PHPickerFilter notFilterOfSubfilter:a]PHPickerFilter.notFilterOfSubfilter(a)
[a isEqual:b]a.isEqual(b)

See also ​