I have a game written in Corona that stores game state data in a json file in system.DocumentsDirectory. When the game starts up, the data in the json file gets loaded into a Lua table. Whenever the data in the Lua table gets updated by the game, the game re-writes the json file in system.DocumentsDirectory with the new data.
Based on what I’ve read, I believe that Corona automatically copies this json file in system.DocumentsDirectory to the user’s iCloud account if he or she has one. I’m assuming that this means that the json file is stored in two places: in the game’s local sandbox on the device and in the user’s iCloud; and that Corona handles the copying of this file back-and-forth entirely on its own. Okay. So far, so good.
My questions arise because iCloud is much more than a backup service and files stored in iCloud are not sandboxed.
(1) Let’s pretend that my game is a universal app (it isn’t) and I install it on my iPhone and my iPad (both of which are logged in to the same iTunes and iCloud accounts). If I play the game on my iPad, new game data will be written to the json file in the game’s local sandbox on the iPad. Corona will then copy this file to my iCloud. If I then go to play the same game on my iPhone, will Corona pull down the json file in my iCloud and write it to the game’s local sandbox on the iPhone? In other words, will I see game progress from the iPad reflected on the iPhone? Or will Corona ignore the json file in my iCloud because it already has a perfectly good json file in the game’s local sandbox on the iPhone? I would test this out myself, but my app isn’t universal and I only have one iPad.
(2) If Corona ignores the json file in my iCloud because it already has a perfectly good json file in the game’s local sandbox on the iPhone, will the version of the json file in my iCloud (which was copied from the iPad) be overwritten once I play and update game state data on the iPhone? Or does Corona maintain two separate json files in my iCloud: one for the game on the iPhone and the other for the game on the iPad?
(3) If Corona does use iCloud to synchronize the json files in my iCloud, on the iPhone, and on the iPad, what happens if the game is being played simultaneously on both the iPhone and the iPad? In Apple’s documentation on implementing iCloud, they state that an event is triggered whenever an app’s file stored in iCloud is modified and that it is up to the programmer to handle the fact that the app’s data has changed. As far as I can tell, there is no way to do this in Corona since everything about iCloud is handled by Corona itself behind the scenes and there is no way to register for this specific event.
Sorry for all these questions. I tried digging through the documentation and forums at the Corona SDK website, but couldn’t find any answers.
Thanks!
Dave [import]uid: 164828 topic_id: 30861 reply_id: 330861[/import]