View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Discover PhotoKit change history

    PhotoKit can help you build rich, photo-centric features. Learn how you can easily track changes to image assets with the latest APIs in PhotoKit. We'll introduce you to the PHPhotoLibrary change history API and demonstrate how you can persist change tokens across launches to help your app recognize additions, deletions, and updates to someone's photo library.

    To learn more about Photos library integration, be sure to watch "What's new in the Photos picker" from WWDC22 and "Improve access to Photos in your app" from WWDC21.

    Recursos

    • PhotoKit
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC23

    • Embed the Photos Picker in your app

    WWDC22

    • What's new in the Photos picker

    WWDC21

    • Improve access to Photos in your app
  • Buscar neste vídeo...
    • 0:01 - Tracking photo library changes

      // Discover added assets
      let options = PHFetchOptions()
      options.predicate = NSPredicate(format: "creationDate > %@", lastLaunchDate as CVarArg)
      let insertedAssets = PHAsset.fetchAssets(with: options)
    • 0:02 - Tracking photo library changes (2)

      let fetchResult = PHAsset.fetchAssets(with: localIdentifiers, options: nil)
      // Discover all modified and deleted assets
      fetchResult.enumerateObjects { asset, idx, stop in
          if asset.modificationDate?.compare(lastLaunchDate) == .orderedDescending {
              // Asset could have been modified
          }
          if !localIdentifiers.contains(asset.localIdentifier) {
              // Asset could have been deleted
          }
      }
    • 0:03 - Fetching persistent changes using persistent change token

      let persistentChanges = try! PHPhotoLibrary.shared().fetchPersistentChanges(since: self.lastStoredToken)
      
      for persistentChange in persistentChanges { 
         if let changeDetails = persistentChange.changeDetails(for: PHObjectType.asset) {
              let updatedIdentifiers = changeDetails.updatedLocalIdentifiers
              let deletedIdentifiers = changeDetails.deletedLocalIdentifiers
              let insertedIdentifiers = changeDetails.insertedLocalIdentifiers
          }
      }
      
      // After processing change details
      self.lastStoredToken = lastPersistentChange.changeToken
    • 0:04 - Identifying important changes

      // Get last stored change token
      let changeToken = self.lastStoredToken
      
      // Fetch persistent changes
      let persistentChanges = try!   
               library.fetchPersistentChanges(since: changeToken)
      
      for persistentChange in persistentChanges {
          // Grab change details and process updates
      }
    • 0:05 - Using inserted identifiers

      let insertedAssets = PHAsset.fetchAssets(with: insertedIdentifiers, options: nil)
      insertedAssets.enumerateObjects { asset, idx, stop in
         for hike in hikes {
              let dateInterval = NSDateInterval(start: hike.startDate, end: hike.endDate)
              if dateInterval.contains(asset.creationDate) {
                  // This hike contains a new added asset
              }
          }
      }
    • 0:06 - Using updated identifiers

      let updatedAssets = PHAsset.fetchAssets(with: updatedIdentifiers, options: nil)
      updatedAssets.enumerateObjects { asset, idx, stop in
          if asset.hasAdjustments {
              // This asset has edits
          }
      }
    • 0:07 - Using deleted identifiers

      for deletedIdentifier in deletedIdentifiers {
          for collage in collages {
              if collage.assetLocalIdentifiers.contains(deletedIdentifier) {
                  // This collage needs to be redrawn
              }
          }
      }
    • 0:08 - Handling errors

      do {
          let persistentChanges = try library.fetchPersistentChanges(since: changeToken)
      } catch PHPhotosError.persistentChangeTokenExpired,
              PHPhotosError.persistentChangeDetailsUnavailable {
          let fetchResult = PHAsset.fetchAssets(with: trackedIdentifiers, options: options)
          // Use fetch result
      }

Developer Footer

  • Vídeos
  • WWDC22
  • Discover PhotoKit change history
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines