iCloud NSUbiquitousKeyValueStore not synchronising

Forums Programming Programming – Everything else iCloud NSUbiquitousKeyValueStore not synchronising

This topic contains 40 replies, has 11 voices, and was last updated by  x0661t 10 months ago.

Viewing 25 posts - 1 through 25 (of 41 total)
Author Posts
Author Posts
November 6, 2012 at 5:17 pm #245180

itlgames
Moderator
@itlgames

I’m working on a game that is trying to sync some NSUserDefault values on iCloud, I’m using the SDCloudUserDefaults (also tried MKiCloudSync), I created the app id on dev portal with iCloud enabled, created a new development provisioning, enabled entitlements on my project summary page and set the key-vcalue store, ubiquity container and keychain groups,… even removed app completely from devices… all done and ticked.

The game runs, no errors, all seems to be working, but I have two devices all both using same iCloud account, all both with the Settings->iCloud->Documents&Data enabled, both under Wifi just in case, but no matter what I do, they don’t synchronise…

Devices are an iPad 1 with iOS 5.1.1 and iPhone 4 with iOS 6.0

Am I missing something?

November 8, 2012 at 1:23 pm #391645

itlgames
Moderator
@itlgames

Anyone? :’(

November 8, 2012 at 1:57 pm #391646

embero
Participant
@embero

Have you switched the signing in XCode to the newly created provisioning profiles?

Otherwise:

1. Remove all associated profiles on your Mac AND in the Developer Portal

2. Create a new Provisioning Profile in the Developer Portal ( iCloud has to be enabled first! )

3. Download and Install the newly created Profiles

4. Set them in XCode under Code-Signing

November 8, 2012 at 7:53 pm #391647

itlgames
Moderator
@itlgames

Yeah I did all that :(

I don’t get any error, and in fact the NSUbiquitousKeyValueStore calls get me values, but just don’t seem to sync with my two devices, I believe it must be something on my devices, but I checked and all seems ok. Does iCloud work on development builds? I hope so! Perhaps we need to do some tricky things, like I remember submitting a binary file for review and reject just to be able to test InApp purchases.

November 8, 2012 at 8:26 pm #391648

Thomvis
@thomvis

Yes, iCloud does work on development builds. It doesn’t work on the simulator for me. No errors, but the cloud is just empty.

Are you sure you aren’t signing your builds with a wildcard profile? IIRC that won’t work.

November 8, 2012 at 8:39 pm #391649

itlgames
Moderator
@itlgames

Yeah I used a full reverse-domain name, so no wildcard, and checking in two real devices. Dunno what else to do, on both my devices I have disabled all iCloud settings except the Documents&Data, and on the Storage & Backup > Manage Storage I can see another game I bough that uses iCloud… sniff :’(

November 8, 2012 at 8:42 pm #391650

Thomvis
@thomvis

And you probably have enabled iCloud and the key-value store with the appropriate identifiers in the settings of your target in Xcode?

I remember when I set up iCloud for my game it took some trail and error.

November 8, 2012 at 9:30 pm #391651

itlgames
Moderator
@itlgames

Yes, done that too. The key-value identifier is the same as the bundle id, not sure if that’s an issue.

November 8, 2012 at 9:54 pm #391652

Thomvis
@thomvis

I use the same key-value identifier as my bundle id as well, so that can’t be the problem.

November 11, 2012 at 3:10 pm #391653

itlgames
Moderator
@itlgames

Actually, something is working, cos if I delete the game from my iPad with iOS 5.1, and reinstall, I get back the status, so means at least on that device is working, but on my other device, an iPhone 4 with iOS 6, is not working, deleted and reinstalled and all status is lost. Both devices are configured the same, and using the same iCloud user, but for some reason my iPhone 4 is not working. So I guess is nothing wrong with the code but with my iPhone.

November 18, 2012 at 5:21 pm #391654

itlgames
Moderator
@itlgames

Ok, finally got it working, I had to remove the iCloud account and add again on my phone and all working now!! The SDCloudUserDefaults is as easy as pie: https://github.com/sdarlington/SDCloudUserDefaults

December 7, 2012 at 1:03 pm #391655

lunarmoon
Participant
@lunarmoon

itigames, you are a genius!! I was banging my head on a wall of metal sharp spikes for a week trying to figure out why iCloud was not working on my app!!!! This solution is genius!!!!!! But in my case, I had to delete in all devices I have. Deleting in one device was not enough. Thanks!

December 7, 2012 at 5:10 pm #391656

itlgames
Moderator
@itlgames

Thanks, glad it helped you!

December 10, 2012 at 12:28 am #391657

eiprol
Participant
@eiprol

Hi there!

Have you tried with MKiCloudSync? I’m getting the same problem;however, deleting and adding the iCloud account didn’t solve anything!

The fact is that iCloud seems to work, because,like you, I also get my saved data when deleting my App and installing it again… but I can’t see anything on iCloud documents, so I think something is wrong! (Until Wednesday won’t have another device to test iCloud sync)

I would like to get MKiCloudSync working instead of trying SDCloudUserDefault…

Any ideas? thanks in advice…

December 10, 2012 at 9:33 am #391658

itlgames
Moderator
@itlgames

You won’t see anything on iCloud documents with NSUbiquitousKeyValueStore but that doesn’t mean is not working, it’s normal. I believe this is only when you sync specific documents. If you delete the app, and install again, and your data is back, that means is working.

December 10, 2012 at 9:51 am #391659

eiprol
Participant
@eiprol

That was my guess… Thank you for answering! I’ve been testing and it works!

By the wayt, in case of conflict, anyone knows what happens with syncing? I mean, if I’ve got a key vale stored on icloud, with a high score, and another

One (smaller but newer) stored locally… Which one will last after a sync with iCloud? (Im usung mkicloud, so it auto sync when reading and writing… Any hint on telling The game which one is the good one?)

December 10, 2012 at 10:05 am #391660

itlgames
Moderator
@itlgames

As far as I know NSUbiquitousKeyValueStore doesn’t understand goods ones, just latest ones, and the sync doesn’t happen immediately, when you sync it saves locally, then at some point will be sync to iCloud, so not really way to assure which one will be sync last. But since this is supposed to use for one single person and multiple devices, is not like you will be playing same app at the same time on two devices (we would do that only when testing)

December 10, 2012 at 10:29 am #391661

eiprol
Participant
@eiprol

I suppose you’re right… My fear was having some conexion issues and the pending data is overwritten by a newer local savedate… (Since, as you said, icloud syncs data when it wants to)

February 1, 2013 at 4:15 am #391662

cheaze
Participant
@cheaze

@itlgames Thanks for your advice and for telling me about SDCloudUserDefaults! I am having an issue though. I’ve done all the steps you’ve mentioned earlier in this post. I also cant seem to get my game to load the data after it has been deleted. I am deleting it from my device and then running it thru xcode onto my device again. Could that be the problem? Does installing it using xcode do some weird install that gets rid of the icloud data?

If thats not the case, I think it has to do with my implementation…

Currently I call [SDCloudUserDefaults registerForNotifications]; in my AppDelegate didFinishLaunching

I also start up my GameManager singleton where I have this code that runs on launch…

-(void) setupPrefs
{

if ([SDCloudUserDefaults objectForKey:@"firstTime"] == NO)
{
//setup initial states on the first run of the app
[SDCloudUserDefaults setBool:YES forKey:@"firstTime"];

//tutorials
[SDCloudUserDefaults setBool:YES forKey:@"playMainTutorial"];
_playMainTutorial = YES;
[SDCloudUserDefaults setBool:YES forKey:@"playMultiplyTutorial"];
_playMultiplyTutorial = YES;
[SDCloudUserDefaults setBool:YES forKey:@"playPillTutorial"];
_playPillTutorial = YES;

//coins (start at 0)
[SDCloudUserDefaults setInteger:0 forKey:@"coins"];
_coinz = 0;
[SDCloudUserDefaults synchronize];
}

else
{
_playMainTutorial = [SDCloudUserDefaults boolForKey:@"playMainTutorial"];
_playMultiplyTutorial = [SDCloudUserDefaults boolForKey:@"playMultiplyTutorial"];
_playPillTutorial = [SDCloudUserDefaults boolForKey:@"playPillTutorial"];
_coinz = [SDCloudUserDefaults integerForKey:@"coins"];
[SDCloudUserDefaults synchronize];
}
}

I think that since this is running right away, the data might not have transferred from icloud yet, and is therefore reset. Could this be the issue? How then should I save and initially set my data?

Thanks :)

February 1, 2013 at 7:54 am #391663

HiRez
Participant
@hirez

By the way, you can peek at the current user’s iCloud dictionary to confirm things if you want. Here’s a method I wrote that prints that dictionary (this prints everything, not just your app, but you could just look at your app’s by getting a sub-dictionary with its key).

- (void)printiCloudDictionary {
NSUbiquitousKeyValueStore *iCloudStore = [NSUbiquitousKeyValueStore defaultStore];
NSDictionary *iCloudDict = [iCloudStore dictionaryRepresentation];
if (iCloudDict) {
NSLog(@"iCloud dictionary contents:%@", [iCloudDict description]);
} else {
NSLog(@"iCloud dictionary not found.");
}
}

February 1, 2013 at 9:15 am #391664

itlgames
Moderator
@itlgames

@cheaze, be sure you tick all these:

- created the app id on dev portal with iCloud enabled

- created a new development provisioning, be sure you update provisioning profiles from Xcode/Organizer (delete any previous one with same name)

- be sure you select the provisioning on the target for the build you using (debug or release)

- enabled entitlements on the project summary page and set the key-value store, ubiquity container and keychain groups,…

- removed app completely from phone and reinstall

- remove the iCloud account and add again on the phone

February 1, 2013 at 7:47 pm #391665

cheaze
Participant
@cheaze

Got it working! I’m not using ARC in my game and I forgot to check if SDCloudUserDefaults was! Once I enabled ARC for DSCloudUserDefaults.m, it works like a champ! (forgetting to check for ARC has bitten me a few times, when will I learn?) Pretty excellent chunk of code he wrote!

In my setupPrefs method, even though it fires right away and possibly overwrites the icloud stored defaults initially, once registerForNotifications finishes running, it replaces those values with the ones from the cloud.

February 20, 2013 at 3:51 pm #391666

bigubosu
Participant
@bigubosu

Is the key-value store, ubiquity container and keychain groups all the same as the bundle ID? I can save it and retrieve but once I delete the app and try to retrieve the data again from iCloud I get null.

ok nvm I think it works

I forgot this:

[SDCloudUserDefaults synchronize];

Will test on another device with the same iCloud account, no one here updates their iOS but me =/..

February 26, 2013 at 11:11 pm #391667

cheaze
Participant
@cheaze

Anyone having problems with icloud restoring information once the app is deleted and then reinstalled after you updated your phone to ios 6.1.2?

I have shared my game with a few friends to test using ad-hoc. Me and one friend both have ios 6.1.2 and we lose our data when we delete and re-install. My other friend who has ios 6.0 said his data is restored fine. We are all using the same build and I had it working great a while back in debug mode (possibly before i updated my ios). Currently icloud doesnt back up in release or debug mode for me.

Not sure if its ios 6.1.2 or not at this point, but I’m super confused why this is happening all of a sudden when it was working fine before.

Thanks for any insight!

February 26, 2013 at 11:59 pm #391668

itlgames
Moderator
@itlgames

Not checked but it’s possible Apple has changed their end, in a way it makes sense to remove iCloud data if you delete you app intentionally, but not nice these backward compatibility issues we are constantly having with them, pretty annoying.

Viewing 25 posts - 1 through 25 (of 41 total)

You must be logged in to reply to this topic.