Accepting a CKShare?

Hi,

I'm starting out with CloudKit Sharing. So far, I managed to get the app to generate a private CKShare and add a participant to it ... I send the link in iMessage to another account, where I can tap the link and it shows me the "Retrieving" message, and then an alert asking if I want to open my app in the Title, and the message says something like "X shared this. You will join as Y (xu@email.com)" .... so I open the app.


At this point, I'm confused... should just opening the link change the 2nd user into Accepted state for the share? If not, what action am I supposed to take to accept the share? The WWDC16 talk glossed over this. According to CloudKit Dashboard, the share's 2nd user is still in "Invited" state, and even going through the code, looking at the share's partipicants list, I can see that acceptanceStatus="Pending". Also, when I use the shareMetadata (from application:userDidAcceptCloudKitShareWithMetadata:) and then fetch the share and root records, using CKFetchRecordsOperation, it fails, and gives me an error "Zone 'MyPrivateZoneName' does not exist" ...



So what am I supposed to do to accept the share? Is there some other API that needs to be called when the link is tapped, after the appdelegate opens application:userDidAcceptCloudKitShareWithMetadata [the name of the API here suggests that the user should be in "accepted" state here, not "pending"]?

Accepted Reply

Hi,


you need to accept the share in the appdelegate method using the CKAcceptSharesOperation:


CKAcceptSharesOperation *operation = [[[CKAcceptSharesOperation alloc] initWithShareMetadatas:shareMetadatas] autorelease];
operation.qualityOfService = NSQualityOfServiceUserInteractive;

operation.acceptSharesCompletionBlock = ^(NSError *operationError)
{
   dispatch_async(dispatch_get_main_queue(), ^{
      //Update your UI and let the user know the share has been accepted
   });
};

[cloudKitContainer addOperation:operation];


Have a look at the CloudKit Videos from WWDC 2016. They describe the flow on how to accept shares in detail.

Replies

Hi,


you need to accept the share in the appdelegate method using the CKAcceptSharesOperation:


CKAcceptSharesOperation *operation = [[[CKAcceptSharesOperation alloc] initWithShareMetadatas:shareMetadatas] autorelease];
operation.qualityOfService = NSQualityOfServiceUserInteractive;

operation.acceptSharesCompletionBlock = ^(NSError *operationError)
{
   dispatch_async(dispatch_get_main_queue(), ^{
      //Update your UI and let the user know the share has been accepted
   });
};

[cloudKitContainer addOperation:operation];


Have a look at the CloudKit Videos from WWDC 2016. They describe the flow on how to accept shares in detail.

Thanks a lot! I missed that when going through the video.

I have this function, but it's not being called. Am I missing something else?