gpt4 book ai didi

ios - GKScore 必须包含一个初始化值?

转载 作者:行者123 更新时间:2023-11-28 22:42:46 25 4
gpt4 key购买 nike

我有时遇到 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/csddavies/DDGameKitHelper/blob/master/DDGameKitHelper.m

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

谢谢!!!

最佳答案

来自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 the reportScoreWithCompletionHandler: method.

很可能是因为您没有设置 value 属性,所以它在提示,但也有可能您也错过了第一步——即它不喜欢您提交 GKScore 来自排行榜的对象,而不是您自己创建的对象。

关于ios - GKScore 必须包含一个初始化值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14035954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com