Any samples for GKSavedGame?

So our most recent app submission was rejected because we allow users to buy virtual coins (they also get them free every hour) and one of the things they can buy with those coins is the ability to "unlock" a category. The reviewer said because they may have bought the coins they treat the categories as a "non-consumable" and therefore we have to save that information so they can retreive it on other devices.


I had a follow up call with a lady at the review board and she said that we could use Game Center to save off the data. I took a look at GKLocalPlayer and there is a function "saveGameData" to save a data buffer to the Game Center cloud. Pretty straight forward even without any documentation. However, getting the data back using GKLocalPlayer fetchSavedGamesWithCompletionHandler is NOT nearly so straight foward. I found this small piece of code for it, but it does not now how to resolve the array.


GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

[localPlayer fetchSavedGamesWithCompletionHandler : ^ (NSArray<GKSavedGame *> * _Nullable savedGames, NSError * _Nullable error)
{
    if (error == nil)
    {
        NSLog(@"%@", savedGames);
    }
    else
    {
        NSLog(@"fetchSavedGamesWithCompletionHandler error: %@", error.description);
    }
}];


I have searched for samples/examples of how to use this to retrieve the data and there is NOTHING that I can find. Nothing in the Xcode docs. Nothing online. Nothing at StackOverflow. Nothing anywhere.


Is anyone using these functions to save to the Game Center cloud? If so, can you provide a code snippet on retrieving the data buffer (and resolving the GKSavedGame data array if there are multiple entries with the same name).


Hard to believe they have something that appears to be really useful, but no samples.


Thanks,


Ken

Replies

It is indeed poorly documented, but if anyone else comes across this issue, i have some snippets to share.
This piece of code is used in our GKNativeExtensions library for Unity, but contains the gist of how these functions work.
https://github.com/dark-1-games/GKNativeExtensions/blob/master/GKNativeExtensions/GKNativeExtensions.mm

We have a single issue, this is also happening in our code:
https://forums.developer.apple.com/message/188277#188277