I am getting a SIGABRT crash sometimes with the crash saying: A GKScore must contain an initialized value.
So it tracked it down to this line:
[localScore reportScoreWithCompletionHandler:^(NSError* error) {}];
And localStore is created like this:
GKScore* localScore = [scores objectForKey:category];
-- category comes from...
for (NSString* category in categories)
-- categories comes from...
[GKLeaderboard loadCategoriesWithCompletionHandler:^(NSArray *categories, NSArray *titles, NSError *error)
-(void) initScores
{
NSString* libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* file = [libraryPath stringByAppendingPathComponent:currentPlayerID];
file = [file stringByAppendingString:kScoresFile];
id object = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if ([object isKindOfClass:[NSMutableDictionary class]])
{
NSMutableDictionary* loadedScores = (NSMutableDictionary*)object;
scores = [[NSMutableDictionary alloc] initWithDictionary:loadedScores];
}
else
{
scores = [[NSMutableDictionary alloc] init];
}
//NSLog(@"scores initialized: %d", scores.count);
}
Sorry for all the code but pretty much all this code comes from this library's file: https://github.com/csddavies/DDGameKitHelper/blob/master/DDGameKitHelper.m
Anyway how would I fix this?
Thanks!!!
From the GameKit reference:
To report a score to Game Center, your game allocates and initializes a new object, sets the
value
property to the score the player earned, and then calls thereportScoreWithCompletionHandler:
method.
Most likely it's complaining because you haven't set the value
property, but it's also possible that you're missing the first step too -- i.e. it doesn't like you submitting GKScore
objects that came from a leaderboard instead of ones you create yourself.