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
  • Get the most out of CloudKit Sharing

    Discover how apps can use CloudKit to share records with others. We'll show you how to encourage collaboration between people using your app and support those interactions with Apple frameworks. Learn how to create and manage shares, explore sharing options like public permissions, and find out how you can use zone sharing in iOS 15 and macOS Monterey to share entire record zones of data.

    To get the most out of this session, we recommend being familiar with CloudKit and a basic understanding of record and data types.

    Recursos

    • CloudKit Samples: Sharing
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC23

    • Sync to iCloud with CKSyncEngine

    WWDC21

    • Build apps that share data through CloudKit and Core Data
    • What's new in CloudKit
  • Buscar neste vídeo...
    • 1:58 - Create a new Contact record

      // Create a new Contact record
      
      func addContact(name: String, phoneNumber: String) async throws {
          let id = CKRecord.ID(zoneID: recordZone.zoneID)
          let contactRecord = CKRecord(recordType: "Contact", recordID: id)
          contactRecord["name"] = name
          contactRecord["phoneNumber"] = phoneNumber
          try await privateCloudDatabase.save(contactRecord)
      }
    • 4:09 - Preparing a CKShare

      // Preparing a CKShare
      
      func createShare(contactRecord: CKRecord) async throws -> CKShare {
          let share = CKShare(rootRecord: contactRecord)
          
          try await privateCloudDatabase.modifyRecords(
              saving: [contactRecord, share], 
              deleting: []
          )
      
          return share
      }
    • 5:25 - UICloudSharingControllerDelegate

      // UICloudSharingControllerDelegate
      
      public protocol UICloudSharingControllerDelegate {
      
          // ...
      
          // Called after the CloudKit sharing controller failed to save the share record.
          func cloudSharingController(UICloudSharingController, failedToSaveShareWithError: Error)
      
          // Called after the CloudKit sharing controller saves the share record.
          func cloudSharingControllerDidSaveShare(UICloudSharingController)
      
          // Called after the user decided to stop sharing the record.
          func cloudSharingControllerDidStopSharing(UICloudSharingController)
      
      }
    • 6:27 - Processing an accepted share invitation

      // Processing a user’s acceptance of a share invitation
      
      func application(
          _ application: UIApplication,
          userDidAcceptCloudKitShareWith shareMetadata: CKShare.Metadata
      ) {
          let container = CKContainer(identifier: shareMetadata.containerIdentifier)
      
          Task {
              do {
                  try await container.accept(shareMetadata)
              } catch {
                  // Handle errors that may occur
              }
          }
      }
    • 7:24 - Fetching shared records

      // Fetching records shared with the current iCloud user
      
      func fetchSharedContacts(in zone: CKRecordZone) async throws {
          var changeToken: CKServerChangeToken? = nil
          var moreChangesComing = true
          
          while moreChangesComing {
              let changes = try await sharedCloudDatabase.recordZoneChanges(
                  inZoneWith: zone.zoneID, 
                  since: changeToken
              )
      
              // Process changes as needed (modifications and deletions)
              processChanges(changes)
                
              moreChangesComing = changes.moreComing
              changeToken = changes.changeToken
          }
      }
    • 9:16 - Search: Phone Number

      // Search by phone number
      
      let phoneNumber = "417-555-9311"
      let participant = try await container.shareParticipant(forPhoneNumber: phoneNumber)
    • 9:16 - Search: Email Address

      // Search by email address
      
      let emailAddress = "dave_knox@icloud.com"
      let participant = try await container.shareParticipant(forEmailAddress: emailAddress)
    • 9:16 - Search: Record ID

      // Search by user record ID
      
      let participant = try await container.shareParticipant(forUserRecordID: recordID)
    • 9:32 - Add participant to a share

      // Add participant to existing CKShare record
      
      func addParticipant(_ participant: CKShare.Participant, to share: CKShare) async throws {
          participant.permission = .readWrite
          share.addParticipant(participant)
          try await privateCloudDatabase.save(share)
      }
    • 9:47 - Confirm invitation acceptance

      // Fetch CKShare.Metadata and confirm accepting share from a given URL
      
      func confirmShareParticipation(from url: URL) async throws {
          let shareMetadata = try await container.shareMetadata(for: url)
          try await container.accept(shareMetadata)
      }
    • 11:14 - Share an entire record zone

      // Create a CKShare sharing an entire record zone
      
      func createAndSaveShare(for zone: CKRecordZone) async throws -> CKShare {
          let share = CKShare(recordZoneID: zone.zoneID)
          try await privateCloudDatabase.save(share)
      
          if share.recordID.recordName == CKRecordNameZoneWideShare {
              // This is managing a shared record zone
          }
      
          return share
      }

Developer Footer

  • Vídeos
  • Tech Talks
  • Get the most out of CloudKit Sharing
  • 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