2

I am trying to store files in my app into CloudKit using CKAssets. Everything work fine, and uploads and downloads using CKRecord + CKAsset is working fine, except for some file types, including Numbers, Keynote and Pages documents. When I try to save these to CloudKit, I get the following error:

CKOperationBase error = <CKError 0x12ddeece0: "Partial Failure" (2/1011); "Failed to modify some records"; partial errors: {
  FileAttachments.169DBAC2-8A14-43F0-9F5A-F851E7FF623B:(CJCloudKitPrivateZoneName:__defaultOwner__) = <CKError 0x12f05dcc0: "Invalid Arguments" (12/1017); "Not a regular file">

My guess is that this has something to do with the files being 'package files' ... i.e. there's a subdirectory hidden underneath them which you can see when you use "Show Package Contacts".

In this case, how should I upload the file to CloudKit? Are there any APIs to detect that these are 'package files', and also to compress them into a format that they can be exported? It would be pretty disappointing if I can't upload a Keynote document on one device and have it accessible (as a Keynote document) on another device through my own app.

Z S
  • 7,039
  • 12
  • 53
  • 105
  • See http://stackoverflow.com/questions/27713479/objective-c-how-to-determine-if-a-folder-is-a-package – rmaddy May 04 '16 at 21:39

2 Answers2

0

No magic solution here, you will have to zip and unzip the package yourself.

Julien
  • 3,427
  • 20
  • 22
0

Found the solution here: https://stackoverflow.com/a/36874037/145552

Basically, using NSFileCoordinator with NSFileCoordinatorReadingForUploading option was the key ... this zips the file if needed, and you can pass the newURL from the block into a CKAsset and it works correctly. I was using NSFileCoordinatorReadingWithoutChanges before I found this solution.

Community
  • 1
  • 1
Z S
  • 7,039
  • 12
  • 53
  • 105