[FIXED] iCloud KVS sync between iOS game and tvOS game does not work

Hi,

I want to add the tvOS binary to my normal iOS binary of “Freeze! 2 - Brothers”.

Users will only have to buy the game once and then they can play on iPad, iPhone and Apple TV. 

For this I will sync the game stats (levels done and level times) across iOS and tvOS versions.

Working so far:

  • automatic sync of game stats between iOS devices, using iCloud KVS
     
  • saving and loading of game stats in the tvOS version, using iCloud KVS

Everything is working beautifully (thanks guys for iCloud support!).

But now the problem:

The game stats between iOS and tvOS are not synced. And that’s the mystery.

I set everything up to share the stats correctly:

  • I use the same iCloud account on all devices, iOS and tvOS - [checked]
     
  • I use the same “iCloud Container” for the iOS and the tvOS App-IDs, both are using the container “iCloud.com.frozengun.freeze2” - [checked]
     
  • both in the iOS and the tvOS version I load and save my table to the same variable “syncedSettingsFreeze2” like this: result = iCloud.get( “syncedSettingsFreeze2” )  - [checked]

I tested all the apps using the distribution ad hoc profiles using the correct Apple IDs with iCloud enabled (otherwise iCloud wouldn’t work for me at all).

In my opinion everything should work, because iCloud KVS IS working on both iOS and tvOS, and the exact same iCloud account and container and variable is used.

But still the game stats between iOS and tvOS are not shared, so they must be written in different places.

Did anyone made it work? Or is there a bug?

Best

Andreas

Thanks for your feedback. KVS store doesn’t use iCloud containers, those are used only by CloudKit and Documents in iCloud. KVS, by default, is using app id instead of containers.
 
You can check which KVS store your app is using with a terminal command:

codesign -d --entitlements :- icloud\_tests\_with\_cloudKit.app

(use your app path/name)

 
It would produce like a page of text. You’re looking for something like

\<key\>com.apple.developer.ubiquity-kvstore-identifier\</key\> \<string\>841FGHF56C.com.coronalabs.iCloudTest\</string\>

(It probably would one before last entry)

String value, between <string> tags, is your KVS store name. If the last part of it is different, you can customize it in build.settings. Instead of writing iCloud=true, replace it with a table, something like

... iphone = { &nbsp; &nbsp; &nbsp;iCloud = {["kvstore-identifier"]="com.coronalabs.MySharedKVS"}, ... } ...

Use same name for tv and iOS. Don’t forget to check both apps with command above, com.apple.developer.ubiquity-kvstore-identifier should be same for both apps.

Cheers! If something needs clarification, don’t hesitate to ask.

EDIT: If you’re using Enterprise, you would have to edit App.entitlements file, and set “iCloud Key-Value Store” value to a specific kvs store name. Usually it is autogenerated from team name and app bundle id using variables.

Hi vlads,

great, this is exactly the info I needed!

Now everything with iCloud KVS works great, my game is perfectly syncing everything back and forth between my iPad, iPhone and Apple TV. 

Maybe add this info into the documentation, too?

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

And many thanks for the detailed answer!

Best

Andreas

Thanks for your feedback. KVS store doesn’t use iCloud containers, those are used only by CloudKit and Documents in iCloud. KVS, by default, is using app id instead of containers.
 
You can check which KVS store your app is using with a terminal command:

codesign -d --entitlements :- icloud\_tests\_with\_cloudKit.app

(use your app path/name)

 
It would produce like a page of text. You’re looking for something like

\<key\>com.apple.developer.ubiquity-kvstore-identifier\</key\> \<string\>841FGHF56C.com.coronalabs.iCloudTest\</string\>

(It probably would one before last entry)

String value, between <string> tags, is your KVS store name. If the last part of it is different, you can customize it in build.settings. Instead of writing iCloud=true, replace it with a table, something like

... iphone = { &nbsp; &nbsp; &nbsp;iCloud = {["kvstore-identifier"]="com.coronalabs.MySharedKVS"}, ... } ...

Use same name for tv and iOS. Don’t forget to check both apps with command above, com.apple.developer.ubiquity-kvstore-identifier should be same for both apps.

Cheers! If something needs clarification, don’t hesitate to ask.

EDIT: If you’re using Enterprise, you would have to edit App.entitlements file, and set “iCloud Key-Value Store” value to a specific kvs store name. Usually it is autogenerated from team name and app bundle id using variables.

Hi vlads,

great, this is exactly the info I needed!

Now everything with iCloud KVS works great, my game is perfectly syncing everything back and forth between my iPad, iPhone and Apple TV. 

Maybe add this info into the documentation, too?

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

And many thanks for the detailed answer!

Best

Andreas