Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problems Retrieving Image From CloudKit Record
Started by niilotippler Mar 12 2019 12:32 PM

No replies to this topic
icloud cloudkit ios cloudkitrecord images database
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

niilotippler

[GLOBAL: userInfoPane.html]
niilotippler
  • Observer

  • 13 posts
  • Corona SDK

Greetings,

 

I am having some problems implementing CloudKit from a simple demo app that I'm building. Here is the premise of what I'm trying to do:

 

1. Select an image from a grid of thumbnails.

2. Save the image, along with some JSON data, using CloudKit to a CK Container.

3. Query CK for a list of records.

4. Fetch a single record and then restore the image and dynamic content from the JSON.

 

I have set up all the back-end and services - iCloud is active, CK Containers are defined, and I can access the database in the CloudKit Dashboard.

 

I can connect to iCloud, verify the connection, and have been able to store a record in the CK database and verify it exists in the Dashboard. The JSON data is in the record, as is the "Asset" field for the image, and when I look at this field it confirms it is an image asset, and I can download it directly from the Dashboard in the browser (although Safari adds the extension .dms for some reason, but if I change it to .jpg then I can open it as a JPG and confirm it is valid).

 

I can query the CK database, and I get returned a list of the records.

 

The problem comes when fetching an individual record and trying to regenerate the image from the asset field as a display.newImage() object.

 

The value I get from the asset field is of type 'path' which is a string. But I don't seem to be able to use this path in any way to retrieve the actual image data.

 

The path returned is in this form:

/private/var/mobile/Containers/Data/Application/C12033DA-704E-46E2-BE21-1D4A9EA1DD52/Library/Caches/CloudKit/cc511d5bd28ff05db9ec339aa1fae98f31edbea8/Assets/65A9DEB6-D945-48D7-BED9-CE44368DC26D.014f0ec990cb5111a4cd008f3e2dceab1720dce7ed

 

Which, so far as I can determine, is supposed to point to temporary cached image data, downloaded from the CK record. From what I've read, the image itself is not named the same as the original, so I can't rely on the saved image's filename, and is not permanent and could be deleted by the system to free-up memory.

 

I've searched the Corona forums and scoured the web for answers, but all of the code I've found which relates to CK record image asset retrieval is either in Swift or Obj-C, and utilizes the CKAsset object and a field called 'fileURL', but this field does not seem to exist within the Corona iCloud plug-in CloudKitRecord structure. In the CK Dashboard, if I look at the 'details' of the Asset field, it displays a 'file checksum' and a 'reference checksum', but again those values do not seem to be accessible from the CloudKitRecord.

 

I've tried just about every combination of system.pathToFile() that I can think of, and using the system.ApplicationSupportDirectory as well as all the other directory paths, and even going so far as to try and force the path into something meaningful, but to no avail.

 

Note: I am building this on a Mac, with an iPad connected, using an Ad-Hoc provisioning profile, and sending the build directly to the device, as I know that iCloud doesn't work in the Corona Simulator.  On my device, I'm connected and logged in to iCloud, and that's all been verified as I can write to CK and get the record data.

 

The only reference I came across in these forums which even comes close to what I'm trying to do is this one:

https://forums.coronalabs.com/topic/69436-accessing-sandbox-directories/

 

The one thing that strikes me as different is that my path starts with "/private/var..." whereas the ApplicationSupportDirectory path is just "/var...", however I don't know if that's a red herring.

 

Can anyone help with this issue?  I'm not sure if perhaps my trying to do this purely in Corona using the iCloud plug-in is asking too much of it, and this is functionality that's better suited to being done as a custom native code plug-in, or if I'm simply missing something obvious in the decoding of the Asset field data.

 

I've been working on this problem for several days now, and I'm starting to go a little insane...

 

Any help or advice would be most appreciated - thank you!

 

Niilo

 

 




[topic_controls]
[/topic_controls]