CKShare.Metadata
An object that describes a shared record’s metadata.
Declaration
class MetadataOverview
A share’s metadata is an intermediary object that provides access to the share, its owner, and, for a shared record hierarchy, its root record. Metadata also includes details about the current user’s participation in the share.
You don’t create metadata. CloudKit provides it to your app when the user taps or clicks a share’s url, such as in an email or a message. The method CloudKit calls varies by platform and app configuration, and includes the following:
For a scene-based iOS app in a running or suspended state, CloudKit calls the windowScene(_:userDidAcceptCloudKitShareWith:) method on your window scene delegate.
For a scene-based iOS app that’s not running, the system launches your app in response to the tap or click, and calls the scene(_:willConnectTo:options:) method on your scene delegate. The
connectionOptionsparameter contains the metadata. Use its cloudKitShareMetadata property to access it.For an iOS app that doesn’t use scenes, CloudKit calls your app delegate’s application(_:userDidAcceptCloudKitShareWith:) method.
For a macOS app, CloudKit calls your app delegate’s application(_:userDidAcceptCloudKitShareWith:) method.
For a watchOS app, CloudKit calls the userDidAcceptCloudKitShare(with:) method on your watch extension delegate.
Respond by checking the participantStatus of the provided metadata. If the status is pending, use CKAcceptSharesOperation to accept participation in the share. You can also fetch metadata independent of this flow using CKFetchShareMetadataOperation.
For a shared record hierarchy, the hierarchicalRootRecordID property contains the ID of the share’s root record. When using CKFetchShareMetadataOperation to fetch metadata, you can include the entire root record by setting the operation’s shouldFetchRootRecord property to true. CloudKit then populates the rootRecord property before it returns the metadata. You can further customize this behavior using the operation’s rootRecordDesiredKeys property to specify which fields to return. This functionality isn’t applicable for a shared record zone because, unlike a shared record hierarchy, it doesn’t have a nominated root record.
The participant properties provide the current user’s acceptance status, permissions, and role. Use these values to determine what functionality to provide to the user. For example, only display editing controls for accepted participants with readWrite permissions.