Share via


CloudKit Namespace

The CloudKit namespace provides access to iCloud.

Classes

Name Description
CKAcceptSharesOperation
CKAllowedSharingOptions
CKAsset
CKContainer
CKContainer.Notifications

Notifications posted by the CKContainer class.

CKDatabase
CKDatabaseNotification
CKDatabaseOperation
CKDatabaseSubscription
CKDiscoverAllUserIdentitiesOperation

An operation that gets all of the discoverable users in the system's address book.

CKDiscoverUserIdentitiesOperation
CKErrorCodeExtensions

Extension methods for the CKErrorCode enumeration.

CKErrorFields

Holds error constants used by CloudKit.

CKFetchDatabaseChangesOperation
CKFetchNotificationChangesOperation

A CKOperation that ret../../summary_set.sh CKFetchNotificationChangesOperation A

CKFetchRecordChangesOperation
CKFetchRecordsOperation
CKFetchRecordZoneChangesConfiguration
CKFetchRecordZoneChangesOperation
CKFetchRecordZoneChangesOptions
CKFetchRecordZonesOperation
CKFetchShareMetadataOperation
CKFetchShareParticipantsOperation
CKFetchSubscriptionsOperation
CKFetchWebAuthTokenOperation
CKLocationSortDescriptor
CKMarkNotificationsReadOperation

Marks push notifications as read. Typically used by apps that use push notifications to track record changes.

CKModifyBadgeOperation

A CKOperation that modifies the badge of the app's icon, either on the current device or all the user's devices.

CKModifyRecordsOperation
CKModifyRecordZonesOperation
CKModifySubscriptionsOperation
CKNotification
CKNotificationID
CKNotificationInfo
CKOperation
CKOperationConfiguration
CKOperationGroup
CKQuery
CKQueryCursor
CKQueryNotification
CKQueryOperation
CKQuerySubscription
CKRecord
CKRecordID
CKRecordValue

This is a class that implements the interface ICKRecordValue (for the protocol CKRecordValue).

Subclass this class to easily create a type that implements the protocol.

An alternative is to create a subclass of NSObject and then implemented the interface ICKRecordValue.

CKRecordZone
CKRecordZoneID
CKRecordZoneNotification
CKRecordZoneSubscription
CKReference
CKServerChangeToken
CKShare
CKShareAccessRequester
CKShareBlockedIdentity
CKShareKeys

Constants used by various CloudKit classes.

CKShareMetadata
CKShareParticipant
CKShareRequestAccessOperation
CKSubscription
CKSyncEngine
CKSyncEngineAccountChangeEvent
CKSyncEngineConfiguration
CKSyncEngineDelegate

This is a class that implements the interface ICKSyncEngineDelegate (for the protocol CKSyncEngineDelegate).

Subclass this class to easily create a type that implements the protocol.

An alternative is to create a subclass of NSObject and then implemented the interface ICKSyncEngineDelegate.

CKSyncEngineDelegate_Extensions

Extension methods to the ICKSyncEngineDelegate interface to support all the methods from the CKSyncEngineDelegate protocol.

CKSyncEngineDidFetchChangesEvent
CKSyncEngineDidFetchRecordZoneChangesEvent
CKSyncEngineDidSendChangesEvent
CKSyncEngineEvent
CKSyncEngineFailedRecordSave
CKSyncEngineFailedZoneSave
CKSyncEngineFetchChangesContext
CKSyncEngineFetchChangesOptions
CKSyncEngineFetchChangesScope
CKSyncEngineFetchedDatabaseChangesEvent
CKSyncEngineFetchedRecordDeletion
CKSyncEngineFetchedRecordZoneChangesEvent
CKSyncEngineFetchedZoneDeletion
CKSyncEnginePendingDatabaseChange
CKSyncEnginePendingRecordZoneChange
CKSyncEnginePendingZoneDelete
CKSyncEnginePendingZoneSave
CKSyncEngineRecordZoneChangeBatch
CKSyncEngineSendChangesContext
CKSyncEngineSendChangesOptions
CKSyncEngineSendChangesScope
CKSyncEngineSentDatabaseChangesEvent
CKSyncEngineSentRecordZoneChangesEvent
CKSyncEngineState
CKSyncEngineStateSerialization
CKSyncEngineStateUpdateEvent
CKSyncEngineWillFetchChangesEvent
CKSyncEngineWillFetchRecordZoneChangesEvent
CKSyncEngineWillSendChangesEvent
CKSystemSharingUIObserver
CKUserIdentity
CKUserIdentityLookupInfo

Interfaces

Name Description
ICKRecordValue

This interface represents the Objective-C protocol CKRecordValue.

ICKSyncEngineDelegate

This interface represents the Objective-C protocol CKSyncEngineDelegate.

Enums

Name Description
CKAccountStatus

Enumerates values that indicate whether a user's iCloud account is available.

CKApplicationPermissions

Enumerates a value that indicates that other app users can discover the current user by email address.

CKApplicationPermissionStatus

Enumerates the states that an application can have when attempting to obtain a permission.

CKDatabaseScope

Enumerates values that tell whether a database is private, shared, or public.

CKErrorCode

Enumerates CloudKit error conditions.

CKNotificationType

Enumerates the events that can generate a push notification.

CKOperationGroupTransferSize
CKQueryNotificationReason

Enumerates the persistent storage events that can trigger data lifecycle notifications.

CKQuerySubscriptionOptions

Enumerates the time or times when a CKSubscription fires a notification.

CKRecordSavePolicy

Enumerates policies that control when or if a record should be saved.

CKRecordZoneCapabilities

Enumerates the special operations that a zone is capable of.

CKRecordZoneEncryptionScope
CKReferenceAction

Enumerates values that control whether a reference should delete itself when its target record is deleted.

CKShareParticipantAcceptanceStatus

Enumerates responses to share participation requests.

CKShareParticipantPermission

Enumerates user share permissions.

CKShareParticipantRole
CKShareParticipantType

Enumerates share participant types.

CKSharingParticipantAccessOption
CKSharingParticipantPermissionOption
CKSubscriptionType

Enumerates subscription types.

CKSyncEngineAccountChangeType
CKSyncEngineEventType
CKSyncEnginePendingDatabaseChangeType
CKSyncEnginePendingRecordZoneChangeType
CKSyncEngineSyncReason
CKSyncEngineZoneDeletionReason

Delegates

Name Description
CKAcceptPerShareCompletionHandler
CKDatabaseDeleteSubscriptionHandler

Completion handler for the DeleteSubscription(String, CKDatabaseDeleteSubscriptionHandler) method.

CKFetchDatabaseChangesCompletionHandler
CKFetchPerShareMetadataHandler
CKFetchRecordChangesHandler

Delegate for the AllChangesReported property.

CKFetchRecordsCompletedHandler

Delegate for the Completed property.

CKFetchRecordZoneChangesFetchCompletedHandler
CKFetchRecordZoneChangesRecordWasChangedHandler
CKFetchRecordZoneChangesTokensUpdatedHandler
CKFetchRecordZoneChangesWithIDWasDeletedHandler
CKFetchShareParticipantsOperationPerShareParticipantCompletionHandler
CKFetchSubscriptionsCompleteHandler

Delegate for the Completed property.

CKFetchSubscriptionsPerSubscriptionCompletionHandler
CKFetchWebAuthTokenOperationHandler
CKMarkNotificationsReadHandler

Delegate for the Completed property.

CKModifyRecordsOperationHandler

Delegate for the Completed property.

CKModifyRecordsOperationPerRecordDeleteHandler
CKModifyRecordsOperationPerRecordSaveHandler
CKModifyRecordZonesHandler

Delegate for the Completed property.

CKModifyRecordZonesPerRecordZoneDeleteHandler
CKModifyRecordZonesPerRecordZoneSaveHandler
CKModifySubscriptionsHandler

Delegate for the Completed property.

CKModifySubscriptionsPerSubscriptionDeleteHandler
CKModifySubscriptionsPerSubscriptionSaveHandler
CKQueryOperationRecordMatchedHandler
CKRecordZoneCompleteHandler

Delegate for the Completed property.

CKRecordZonePerRecordZoneCompletionHandler
CKShareRequestAccessOperationPerShareAccessRequestCompletionHandler
CKShareRequestAccessOperationShareRequestAccessCompletionHandler

Remarks

The CloudKit namespace allows application developers to control the flow of data between their applications and iCloud. iCloud provides server-side data storage, both "public" that is shared between all instances of an application or specific applications and "private" that is unique to a single user. iCloud storage and transport is encrypted and synchronized between Apple devices. CloudKit does not provide client-side persistence or data caching -- CloudKit functionality is only available while the user has an active Internet connection.

The highest-level class in the CloudKit is CKContainer. A CloudKit Container (sometimes referred to in Apple documentation as a "Ubiquity container") is an information store identified with a particular name. Apple advises using a name of the form "iCloud.{reverse DNS}.{appName}", for instance, "iCloud.com.mycompany.MyApp". Developers must create and configure their containers using the iCloud Dashboard, available by way of the Apple developer portal.

A single CKContainer may contain both public data, which is shared between all instances of the app (see PublicCloudDatabase), and private data, which contains user-specific data (see PrivateCloudDatabase). Within iCloud, public data is stored in the app's iCloud storage while private data is stored in the user's private iCloud storage. The public CKDatabase is available to all connected users of the app, whether or not they are logged in to iCloud. The private CKDatabase is only available if the user is logged in to iCloud. Developers must write their code such that it reacts gracefully to changes in the user's login or connection status.

These public and private CKDatabase objects store structured records. These are represented by CKRecord objects. In addition to field-like key-value data, these records may hold CKAsset large objects either directly (retrieved with the containing CKRecord) or as references (allowing lazy retrieval of the large data).

All CKRecord instances are stored within a CKRecordZone. A CKRecordZone is something like a traditional database instance: it can contain multiple CKRecord stores that may refer to each other but not to stores in other CKRecordZone instances and CKRecordZone objects can be used to coordinate atomic operations across multiple CKRecord stores. The similarity to a database instance is not universal; for instance, a developer may use FetchRecordAsync to retrieve a CKRecord directly from the CKDatabase without referring to the zone. The default CKRecordZone is available via DefaultRecordZone. Developers may create additional zones using the CloudKit dashboard and use them to partition their data logically.

CloudKit apps require a provisioning profile with the com.apple.developer.icloud-services entitlement and an app-specific Bundle Identifier (e.g., "com.mycompany.CloudKitApp"). Developers must create and configure such a provisioning profile.

The following demonstrates some typical uses of CloudKit that work on single records:

//Create
private async Task<CKRecord> StoreInCloudKit (string name, CLLocation loc, int stationId)
{
    string containerName = "iCloud.com.example.CKWork";
    var container = CKContainer.FromIdentifier (containerName);
    CKDatabase publicDatabase = container.PublicCloudDatabase;
    var zoneId = CKRecordZone.DefaultRecordZone ().ZoneId;
    var recordType = "StationReferences";

    var record = new CKRecord (recordType);
    record ["Name"] = new NSString (name);
    record ["Position"] = loc;
    record ["StationID"] = new NSNumber (stationId);

    var storedRecord = await publicDatabase.SaveRecordAsync (record);
    return storedRecord;
}

//Retrieve (via ID)
private async Task<CKRecord> AccessCloudKit ()
{
    string containerName = "iCloud.com.example.CKWork";
    var container = CKContainer.FromIdentifier (containerName);
    CKDatabase publicDatabase = container.PublicCloudDatabase;

    var recordNameIHappenToKnow = "7eaf0432-2fa4-475f-851a-c6a19b3f8587";
    var recordId = new CKRecordID (recordNameIHappenToKnow);
    var record = await publicDatabase.FetchRecordAsync (recordId);

    return record;
}

//Retrieve (query)
private async Task<CKRecord []> QueryCloudKit ()
{
    string containerName = "iCloud.com.example.CKWork";
    var container = CKContainer.FromIdentifier (containerName);
    CKDatabase publicDatabase = container.PublicCloudDatabase;

    var zoneId = CKRecordZone.DefaultRecordZone ().ZoneId;
    Console.WriteLine ($"Default zone name = '{zoneId.ZoneName}' owner = '{zoneId.OwnerName}'");
    /*
    var zoneName = "_defaultZone";
    var ownerName = "__defaultOwner__";
    var zoneId0 = new CKRecordZoneID (zoneName, ownerName);

    Console.WriteLine ($"Assert { zoneId0 == zoneId }");
    */

    var recordType = "StationReferences";

    var location = new CLLocation (19.7303, -155.056);
    var predicate = NSPredicate.FromFormat ("distanceToLocation:fromLocation:(Position, %@) < 100", location);

    var query = new CKQuery (recordType, predicate);

    var result = await publicDatabase.PerformQueryAsync (query, zoneId);
    return result;
}

//Update
private async Task<CKRecord> UpdateInCloudKit (CKDatabase database, CKRecord record, NSString key, NSObject newValue)
{
    record [key] = newValue;
    var modifiedRecord = await database.SaveRecordAsync (record);
    return modifiedRecord;
}

//Delete
private async Task<CKRecordID> DeleteRecord (CKDatabase database, CKRecord record)
{
    var id = record.Id;
    var deletedId = await database.DeleteRecordAsync (id);
    return deletedId;
}