iCloud KVS between iOS and OSX app

So… I need data to be synced between my iOS app and the cooresponding OSX one.  Looks like we need to be able to change the Key-Value store manually in the  .entitlements  file…  Here’s something that I found.  

 

Perry or anyone else at Corona - any insight into if this is possible or how I’d be able to do this for a Corona iOS and a cooresponding OSX app?

 

http://stackoverflow.com/questions/18265132/sharing-icloud-data-between-an-ios-app-and-an-osx-app-with-nsubiquitouskeyvalues

 

Thanks,

Nate

Nevermind - found it :wink:   

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

If using only KVS, you can share data between different apps by specifying a kvstore-identifier in the iphone table of build.settings. This will override the default boolean true which simply enables KVS for the same app on the user’s iCloud-enabled devices.

So actually this does NOT work for OSX - at least yet… My already-released Corona iOS app uses KVS storage, but I need my OSX app to share that same data.  

The OSX build doesn’t seem to utilize this in my build.settings:

["kvstore-identifier"] = "com.mycompany.iosapp"

You can do that, only in case your app is on OS X Mac App Store.

edit: you can use iCloud only if your app is distributed through OS X Mac App Store, no iCloud for Self Distributed apps.

Interesting… so would you have any recommendations on how to test this before the app is live and distributed via the Mac App Store?

Thanks,

Nate

Unfortunately we don’t support developer profile at this point - we have only self distribution and app store distribution. iCloud will have same behaviour as does on iOS and tvOS.

We may add entitlements for developer profiles sometime.

I just noticed something bad. May I ask to do same with tomorrows daily build? There is something weird about OS X provisioning profiles, and I added workaround. Current build can result in bad entitlements (you’ll get error message in console, but build will succeed)

Hi that sounds great…  do you know about what time the new daily build will be available?  Thanks

Thanks for you patience. It seems we have some problem with code-signing still… Daily build may or may not fix it.

Thanks…  appreciate you guys working on this issue.

For your reference, I ran this on my OSX distribution provisioning profile:

security cms -D -i c7c1003b-430c-43c3-bec4-03a3eec22f38.provisionprofile 

And it printed out a bunch of stuff, in which I could see the “Entitlements” entry…  in that for the kvstore-identifier, it had a wildcard.  For reference below, I masked out the actual team ID it put…

\<key\>com.apple.developer.ubiquity-kvstore-identifier\</key\> \<string\>MYTEAMID.\*\</string\>

When I’m building the OSX and selecting the “Open Application” option in the build dialog, I’m monitoring the console and get the following.   Again, for privacy I masked out the actual bundle ID…

NSUbiquitousKeyValueStore error: com.mycompany.myapp.osx does not have a valid com.apple.developer.ubiquity-kvstore-identifier entitlement

OK. Tanks for your patience. It seems that 2016.2846 signs a valid binary, with proper entitlements for KVS and other iCloud services. Sorry for inconvenience. Download latest build and try again.

Reminder. To make OS X synchronize between iOS and tvOS you’ll have to set it’s kvs store ID, because OS X app probably will have different app ID that your iOS/tvOS app which can share it. Here’s small example (for explanations look on iCloud plugin doc page); distilled version of build.settings from Corona Cannon:

[lua]

settings = {

    iphone = {

        iCloud = true,

    },

    tvos = {

        iCloud = true,

    },

    osx = {

        iCloud = {[‘kvstore-identifier’] = ‘com.coronalabs.coronacannon’},

    },

    plugins = {

        [‘plugin.iCloud’] = {publisherId = ‘com.coronalabs’, supportedPlatforms = {iphone = true, appletvos = true, osx = true}},

    },

}

[/lua]

Thanks!!  I’m digging into this this morning and will report back here when all is good to go…

Ok…  so here’s the scoop.  

For reference sake below, my bundle ID for my iOS game is com.mycompany.myapp and the one for my OSX game is com.mycompany.myapp.osx.

I’ve updated my build.settings to coorespond with how you have it set up in the Cannons project.   In the “iphone” part, I have “iCloud = true”.  Then, I added this for the osx part…

osx = { iCloud = { ['kvstore-identifier'] = 'com.mycompany.myapp' } },

When I build for OSX using the “Open Application” command in the build dialog, watching the console produces this:

NSUbiquitousKeyValueStore error: com.mycompany.myapp.osx does not have a valid com.apple.developer.ubiquity-kvstore-identifier entitlement

Inside the app though, with iCloud sync enabled and apparently running, it’s working…  I can clear out settings and then turn iCloud sync back on inside my game (I have an option to turn it on or off in the game).  After I’ve cleared out the game settings/cache and checked it, there is no progress saved.  Then, when iCloud sync is turned back on, it updates from iCloud.  What this indicates to me is that it’s pulling from *somewhere*, but not my com.mycompany.myapp bundle ID  (my iOS version of the game)…

Is this simply due to the fact that I’m not getting my game legitimately from the Mac App Store, but from a local developer build?  You’d mentioned earlier that the app needs to formally come from the Mac App Store to be able to have iCloud work.   However, in my testing here it does appear to be working, but just not pulling from the iOS KVS store that I’m wanting to pull from.  It seems to be pulling from only the OSX store…

And then there’s that strange “NSUbiquitousKeyValueStore” error too that I’m getting…

Again: we would embed entitlements required only if you select option  “Send to Mac App Store…”, and it would work only when you download the app from App Store. Maybe you can manage to get it working locally, but I don’t know how. Note, that only packaged app would have entitlements set up. Entitlements are added on 2nd stage of packaging for the store.

iCloud works only for Mac App Store apps, for now we don’t have to test them for OSX locally.

You can check entitlements for your iOS, tvOS and OS X apps with commands I provided before. To do that you’ll have to unarchive packages if apps were packaged for App Store.

(for OS X, unarchive PKG, I use “The Unarchiver”, then right lick on unpacked package, select show contents, rename Payload to Payload.zip and unpack again) 

Hey there, I ran the test you suggested and tested the unarchived build… running the codesign command produced the correct iOS bundle ID assigned as the KVS identifier.  Going to submit to the Mac App Store and will let you know how it goes!  Thanks again.

I’m pleased to announce that Alpha Omega for OS X has been submitted successfully and is currently awaiting review in the Mac App Store :slight_smile:  Thanks again for your help!

Nevermind - found it :wink:   

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

If using only KVS, you can share data between different apps by specifying a kvstore-identifier in the iphone table of build.settings. This will override the default boolean true which simply enables KVS for the same app on the user’s iCloud-enabled devices.

So actually this does NOT work for OSX - at least yet… My already-released Corona iOS app uses KVS storage, but I need my OSX app to share that same data.  

The OSX build doesn’t seem to utilize this in my build.settings:

["kvstore-identifier"] = "com.mycompany.iosapp"

You can do that, only in case your app is on OS X Mac App Store.

edit: you can use iCloud only if your app is distributed through OS X Mac App Store, no iCloud for Self Distributed apps.

Interesting… so would you have any recommendations on how to test this before the app is live and distributed via the Mac App Store?

Thanks,

Nate