The abstract base class for all operations that can be executed against a CloudKit database.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 3.0+
All CloudKit operation objects descend from
CKOperation, which provides the infrastructure for executing tasks against one of your app’s containers. Do not subclass or create instances of this class directly. Instead, create instances of one of its concrete subclasses.
Use the properties of this class to configure the behavior of the operation object before submitting it to an operation queue or executing it directly. CloudKit operations involve communicating with the iCloud servers to send and receive data. The properties of this class let you configure the behavior of those network operations to ensure the best performance for your app.
A long-lived operation is an operation that continues to run after the app exits. To specify a long-lived operation, set the
is property to
true, set the operation completion block, and run it. Later, get the long-lived operation identifiers using the
fetch method in the
CKContainer class. To get the associated operation object, use the
fetch method. Then set the completion block of the long-lived operation so that your app instance receives the callbacks. Otherwise, your app won’t be notified when a long-lived operation completes and won’t be able to process the results.
This is the typical life cycle of a long-lived operation:
The app creates a long-lived operation and runs it.
The daemon starts saving and sending the callbacks to the running app.
The app exits.
The daemon continues running the long-lived operation and saves the callbacks.
The app launches and fetches the long-lived operation.
If the operation is running or if it completed less than 24 hours ago, the daemon returns a proxy for the long-lived operation. If the operation completed over 24 hours ago, the daemon may stop returning it in fetch requests.
The app runs the long-lived operation again.
The daemon sends the app all the saved callbacks (it doesn’t actually re-run the operation), and continues saving the callbacks and sending them to the running app.
The app receives the completion callback or the app cancels the operation.
The daemon stops including the operation in future fetch results.