iCloud Questions

Hi,

I have a couple of questions relating to the iCloud plugin.

I’ve got it working nicely between 2 of my iOS devices with a simple example based on this tutorial - https://coronalabs.com/blog/2015/12/18/tutorial-implementing-icloud-key-value-storage/

I’m looking at porting one of our apps that currently uses a local sqlite database to store user progress and stats on a single device to use iCloud to share progress across devices. In terms of storing tabular data, am I best using Key-Value storage with Corona tables or is there a way of actually storing a sqlite table in the cloud?

Secondly, is there a way to test iCloud in the simulator. I get the error “WARNING: iCloud plugin would not work in Corona Simulator.”

Appreciate that iCloud needs you logged in with an Apple account to work but I wondered if there was any way that allowed me to link my Apple ID to my installation of the Corona simulator somehow so I could test. A pain having to install onto a device every time you want to test.

I’m using the latest daily build.

Thanks,

Ian

Problem is Corona Simulator is not a iOS App. And to use your KVS storage it has to be signed with your certificate. But Corona Simulator is Corona Labs app, and only access it can get is to the Corona Labs KVS storage/iCloud.

Secondly, only apps distributed through Mac App Store can access iCloud, and Corona Simulator isn’t.

Even if we would distribute Corona Simulator through Mac App Store, it wouldn’t be safe to give programmable access to shared Simulators iCloud access, because some iCloud services require admin access to https://icloud.developer.apple.com/dashboard/ which is out of the question to make public.

My point is that iCloud by design is supposed to work only on your apps. We could emulate KV storage with tables, but I see that as misleading, because KVS storage has it’s trick and hidden pitfalls due to distributed nature and synchronization.

Only suggestion I can offer it to use Xcode Simulator for your tests. iCloud stuff should work in it.

Thanks - totally get that. Will try the Xcode simulator.

Actually, there is a way to reduce iteration cycles greatly. It’s using Corona Viewer. Corona Viewer is an app which would do live updates on your device and code will be synced via Dropbox.

Here’s blog post about it https://coronalabs.com/blog/2014/06/26/coronaviewer-instant-on-device-previews/

Wha you’ll have to do, is download Github project, and add your iCloud credentials to it: like iCloud=true, iCloud plugin, and build with provisioning profile used for your app. Also, you can replace config.lua. Make sure that you have original Viewer’s main.lua and viewer plugin in build settings. After that deploy Corona Viewer to the device, start it and log into Dropbox. It will create Apps/CoronaViewer folder. Copy your app there, and wait for it to sync up with dropbox. When sync is done, Viewer would update it’s contents.

I debugged my iCloud test app when was developing a plugin.

So, even if you can’t get iCloud in simulator, you can reduce need to deploy to device every small change. Note that Viewer has to be built with plugins and profile you’re using in your project. build.settings contents can’t be updated via Dropbox.

Cheers & Good luck!

Thanks - I’ll look into it.

In terms of my other question re: syncing larger amounts of data, does anyone have any opinion on the most efficient way to achieve this? Is CloudKit the right approach for storing database-like sets of data?

Thanks.

iCloud KVS can store up to 1000 records up to 1mb in total. It is up to you if you want to store whole 1mb in a signle key, or in separate. Separate KV keys are synced separately.

I recommend reading this document: https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForKey-ValueDataIniCloud.html

I’m looking at porting one of our apps that currently uses a local sqlite database to store user progress and stats on a single device to use iCloud to share progress across devices. In terms of storing tabular data, am I best using Key-Value storage with Corona tables or is there a way of actually storing a sqlite table in the cloud?

 I am looking for an answer to the above question in this thread. How can I use iCloud to share a database across devices such as sqlite?

Thanks!

The iCloud plugin has three modes of storage:

  1. Key-value pairs

  2. Documents

  3. Distributed Database

Since I don’t know what you’re storing in your SQLite database, this may be a bit vague.

If you’re using the SQLite database to store game settings, then key-value storage may be the easiest thing to do. It’s not for lots of data, but is great for settings. For small amounts of data and if there are not multiple records and multi-table relationships. This is probably the way to go.

Databases tend to be used to store lots of information and be able to search for a smaller subset of that data and/or have relationships between multiple tables of data to create complex data structures. If you absolutely need this to be an SQLite database then perhaps #2 Document storage might work for you. The whole database file would be stored to the cloud and synched between the shared accounts. The drawback here is if multiple devices make updates, which file is the right file? It may be hard to keep an SQLlite database synced up.

The third option, if you have multiple records and or multiple tables is to switch from SQLite to CloudKit’s distributed database. Your tables with multiple records exist in the cloud and you query the cloud much like you would query a local database.

The documentation should cover all three modes and what you need to do to use it:

https://docs.coronalabs.com/daily/plugin/iCloud/index.html

Rob

Thanks Rob. Can you give me a little direction on how I can implement CloudKit’s distributed database and if I can use the same queries I used with SQLite?

Thanks!

It does not use an SQL like query language from what I can tell. It looks like we have API’s to perform the CRUD operations (Create, Read, Update, Delete). I’m asking to see if we have a sample app that covers that part of iCloud.

Rob

Here is some example code we used to test iCloud. You should be able to adapt from that:

https://gist.github.com/Shchvova/11bd3314bf546483eb7932620d4feb39

Rob

Thanks so much Rob! This is very helpful.

That example is very basic, unfortunately I don’t seem to be able to find more elaborate sample. Anyway, to better understand how to use CloudKit I would highly recommend to look through this document

https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/

It is written in easy language, and translates transparently into plugin.iCloud calls.

Thanks lads! This is very helpful too, but does not show how to create a cloudkit database using Corona.

Is there a way to check if iCloud exists and is active on the user’s device? I want to setup a global boolean variable.

One more question: is it possible to load a binary file such as an image to iCloud?

Yes. I seriously recommend reading documentation.

CoudKit has both asset storage, where you give path to file, and binary data store, where you can just store blobs. 1st is preferable for images. I had demo using it, but I can’t find it :frowning: