简体   繁体   English

GKScore必须包含初始值?

[英]A GKScore must contain an initialized value?

I am getting a SIGABRT crash sometimes with the crash saying: A GKScore must contain an initialized value. 我有时会因为崩溃而得到SIGABRT崩溃:GKScore必须包含初始值。

So it tracked it down to this line: 所以它追踪到这条线:

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

And localStore is created like this: localStore是这样创建的:

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 很抱歉所有的代码,但几乎所有这些代码都来自这个库的文件: https//github.com/csddavies/DDGameKitHelper/blob/master/DDGameKitHelper.m

Anyway how would I fix this? 无论如何,我该如何解决这个问题?

Thanks!!! 谢谢!!!

From the GameKit reference : GameKit参考

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 the reportScoreWithCompletionHandler: method. 要向游戏中心报告分数,您的游戏会分配并初始化一个新对象,将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 -- ie it doesn't like you submitting GKScore objects that came from a leaderboard instead of ones you create yourself. 很可能它抱怨因为你没有设置value属性,但你也可能错过了第一步 - 也就是说它不喜欢你提交来自排行榜的GKScore对象而不是你自己创建的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM