在iOS 9中向GameCenter报告得分(xCode 7.1.1)

所以我有一个完成的游戏,我只是在提交到App Store之前整理一下。

由于我完成了大部分编码,我已经将xCode更新为7.1.1,将我的设备从8.1更新到iOS 9.1。

我学到的第一件事是游戏中心没有沙箱切换(这是我最常使用的没有问题)

现在,当我运行应用程序时,使用此代码报告分数时:

-(void)reportScore{ GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier]; this_score.value = gameScore; [GKScore reportScores:@[this_score] withCompletionHandler:^(NSError *error) { if (error != nil) { NSLog(@"%@", [error localizedDescription]); } }]; NSLog(@"Reported to Game Center..."); } 

我将此错误打印到控制台:

 *** Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A GKScore must specify a leaderboard.' *** First throw call stack: (0x184e60f48 0x199a13f80... ...0x1000d9748... ...0x19a2628b8) libc++abi.dylib: terminating with uncaught exception of type NSException 

其中表示, GKScore必须指定leaderboard ……

我很困惑,因为直到我更新到iOS 9,这个工作正常。

我一直在阅读一堆关于iOS 9中沙箱合并的内容,但我并不了解所有内容。

从我可以收集到的内容,它被合并到现实生活中的帐户中,所有沙箱数据都被删除,测试是在真实的排行榜上进行的? 我可能错了。 就像我说的,我不是100%关于这一点。

我怎么解决这个问题? 我不确定找到准确资源的正确术语……我刚刚用Google搜索了很多年。

也许我需要在本地指定我的LeaderboardIdentifier?

提前致谢。

UPDATE

这比我想象的还要糟糕…当我试图打开/提交给Game Center时,App Store中的所有应用程序都崩溃了?

自从读完这本书以来,我只想考验一下……

是否有更清洁或更新的方法来实施Game Center?

所以,我有一个工作…似乎工作。 我会在接下来的几个小时(或几天)内相应更新……

我的预感是正确的,如果我在方法中使用字符串指定LeaderboardIdentifier ,它现在看起来像这样:

 //GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier]; GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:@"myGameLeaderboardID"]; 

我还包括了方便的NSLogs ,我的callmethod如下所示:

 -(void) GameOver { . . . if(_gameCenterEnabled){ NSLog(@"--Reporting Score to Game Center..."); [self reportScore]; } } -(void)reportScore{ NSLog(@"--- Got to the method"); GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:@"Enemies_Located"]; NSLog(@"---- Alloc GKScore done"); this_score.value = gameScore; NSLog(@"----- Score assigned to GKScore"); [GKScore reportScores:@[this_score] withCompletionHandler:^(NSError *error) { if (error != nil) { NSLog(@"%@", [error localizedDescription]); } }]; NSLog(@"Reported to Game Center..."); } 

这导致以下控制台打印出来:

 2015-12-07 23:20:24.666 myGame[88.....48] Some InGame Ref: 15 2015-12-07 23:20:24.704 myGame[88.....48] --Reporting Score to Game Center... 2015-12-07 23:20:24.704 myGame[88.....48] --- Got to the method 2015-12-07 23:20:24.705 myGame[88.....48] ---- Alloc GKScore done 2015-12-07 23:20:24.705 myGame[88.....48] ----- Score assigned to GKScore 2015-12-07 23:20:24.705 myGame[88.....48] Reported to Game Center... 

这绝不是解决这个问题的正式方法,它围绕着很多人现在所拥有的论坛,因此我为什么要在几天内没有回答这个问题……但它似乎对我有用。 如果您对此有任何好运,请告诉我,或者您知道为iOS 9实现此更好的方法。

同时,我应该现在更新我的所有应用程序-_-