0

我有时会遇到 SIGABRT 崩溃,崩溃时说:GKScore 必须包含一个初始化值。

所以它追踪到这一行:

[localScore reportScoreWithCompletionHandler:^(NSError* error) {}];

localStore 是这样创建的:

GKScore* localScore = [scores objectForKey:category];

-- 类别来自...

for (NSString* category in categories)

-- 类别来自...

[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);
}

对不起所有的代码,但几乎所有这些代码都来自这个库的文件:https ://github.com/csdavies/DDGameKitHelper/blob/master/DDGameKitHelper.m

无论如何,我将如何解决这个问题?

谢谢!!!

4

1 回答 1

2

来自GameKit 参考

要向 Game Center 报告分数,您的游戏会分配并初始化一个新对象,将value属性设置为玩家获得的分数,然后调用该reportScoreWithCompletionHandler:方法。

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.

于 2012-12-26T07:46:59.663 回答