Playerprefs and multitasking

Hi,

In a game I made for a client, I’m getting some reports of user’s scores being deleted when they upgrade the game.
I’ve been trying to figure out why, and one of the scenarios that I came up with is that those scores were never saved to disk. I’m not sure if this is possible, but it could be that they suspended the app (pressed home but not really closed it), and then later updated.

Is this possible, or does Unity save the playerprefs when the app goes to the background?

Thanks!

Depends on your version. There used to be a bug up to 3.1 or 3.2 where it was not correctly saved upon the reception of going into background. 3.3 solved it (added a “safety NSUserDefaults sync” in the handler in the appcontroller.)

Thanks, then that could explain it. The previous versions were built using 3.2. The latest update was built using 3.3, so I hope this is solved now.
I can’t find any code in the appcontroller for this though, so should I add it manually just to be sure? Found this code while doing research about this yesterday:

- (void)applicationDidEnterBackground:(UIApplication*)application
{
    [[NSUserDefaults standardUserDefaults] synchronize];
}

I’d hate to add it and then have it sync twice…

nothing can go wrong by it syncing twice actually, as NSUserDefaults is an iOS integrated store (its omnipresent for the app and always kept in RAM from the moment on the app starts to its end - syncronize ensures the version on the file system is up to date too)