apple / sample-cloudkit-sync-engine

MIT License
176 stars 13 forks source link

CloudKit Samples: CKSyncEngine

Goals

This project demonstrates using CKSyncEngine to sync data in an app.

Prerequisites

Note: CKSyncEngine relies on remote notifications in order to sync properly. Simulators cannot register for remote push notifications, so running this sample on a real device or Mac is required for this app to properly sync.

Setup Instructions

  1. Ensure you are logged into your developer account in Xcode with an active membership.
  2. In the “Signing & Capabilities” tab of the SyncEngine target, ensure your team is selected in the Signing section, and there is a valid container selected under the “iCloud” section.
  3. Ensure that all devices are logged into the same iCloud account.

Using Your Own iCloud Container

How it Works

Example Flow

  1. Run the app on a device or Mac. Latest changes are fetched from the server.
  2. Repeat the above on another device and add a new contact through the UI.
  3. The first device fetches the changes and shows the contact in the UI.

Tests

This project includes a few basic tests for CKSyncEngine integration in SyncTests.swift. This shows one possible way to test your CloudKit sync code by simulating multiple devices syncing back and forth. The test suite only exercises a few basic scenarios, and there are many more complex scenarios to test in your own application.

Things To Learn

Further Reading