PHPhotoLibraryPersistentChangesObserver description

What is the intended purpose of the new PHPhotoLibraryPersistentChangesObserver?

I currently use PHPhotoLibraryChangeObserver as a trigger, then call fetchPersistentChanges(since:). What behavior or guarantees differ when using PHPhotoLibraryPersistentChangesObserver instead?

Thanks!

Answered by Frameworks Engineer in 892540022

Hi,

PHPhotoLibraryPersistentChangesObserver and register(_ observer: any PHPhotoLibraryPersistentChangesObserver) are intended for lightweight notifications when you are working with persistent history and a PHChange is not needed from PHPhotoLibraryChangeObserver. It is also intended to avoid polling fetchPersistentChanges(since:).

Some documentation is available on the register(_:) method:

https://developer.apple.com/documentation/photos/phphotolibrary/register(_:)-7lhue

Hi,

PHPhotoLibraryPersistentChangesObserver and register(_ observer: any PHPhotoLibraryPersistentChangesObserver) are intended for lightweight notifications when you are working with persistent history and a PHChange is not needed from PHPhotoLibraryChangeObserver. It is also intended to avoid polling fetchPersistentChanges(since:).

Some documentation is available on the register(_:) method:

https://developer.apple.com/documentation/photos/phphotolibrary/register(_:)-7lhue

Thanks, that makes sense.

Does PHPhotoLibraryPersistentChangesObserver provide any coalescing/backpressure guarantees, or should I still debounce notifications and prevent overlapping fetchPersistentChanges(since:) calls?

With PHPhotoLibraryChangeObserver I currently treat the callback only as a wake-up signal, debounce bursts of notifications, then call fetchPersistentChanges(since:) once after a quiet window. When migrating to PHPhotoLibraryPersistentChangesObserver, should I expect one notification per persistent history update, coalesced notifications, or just “history advanced, fetch when convenient” semantics?

Accepted Answer

There are no coalescing guarantees for PHPhotoLibraryPersistentChangesObserver, so debouncing like you do for PHPhotoLibraryChangeObserver seems reasonable.

That said, there should be no overlapping calls to photoLibraryPersistentChangesDidUpdate(_:). In other words, you should not see a call to photoLibraryPersistentChangesDidUpdate() while you are already handling a call.

PHPhotoLibraryPersistentChangesObserver description
 
 
Q