问题
So I have a finished game, which I'm just tidying up before submitting to the App Store.
Since I finished the majority of the coding, I've updated xCode to 7.1.1 and my device to iOS 9.1 from 8.1.
The first thing I've learnt is there's no Sandbox toggle in Game Center (which is what I've mostly always used with no problems)
Now, when I run the application, when it comes to reporting a score using this code:
-(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...");
}
I get this error printed to the console:
*** 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
which states, a GKScore
must specify a leaderboard
...
I'm confused, because up until I updated to iOS 9, this worked fine.
I've been reading a bunch about the merging of sandbox in iOS 9, but I don't understand all of it.
From what I can gather, it's merged into real-life accounts, all sandbox data is deleted and testing is done on real leaderboards? I may be wrong. Like I said, I'm not 100% about this.
How can I solve this problem? I'm not sure of the correct terminology to find accurate resources... I've just been wildly googling for ages.
Maybe I need to specify my LeaderboardIdentifier locally?
Thanks in advance.
UPDATE
This is even worse than I thought... All my apps that are in the App Store now crash when trying to open/submit to Game Center...?
I only just thought to test them since reading this...
Is there a cleaner or more updated method of implementing Game Center?
回答1:
So, I have a work around... that appears to be working. I will update accordingly over the next few hours (or days)...
My hunch was right, and if I specify the LeaderboardIdentifier
using a string inside the method, it now looks like this:
//GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier];
GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:@"myGameLeaderboardID"];
And with the handy NSLogs
I also included, my call
& method
looks like this:
-(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...");
}
Which results in the following console print out:
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...
This is by no means an official way to fix this issue, which looking around forums a lot of people are now having, hence why I'm leaving this question unanswered for a few days... but it seems to be working for me. Please let me know if you have any luck with this too, or you know of a better way to implement this for iOS 9.
Mean while, I should probably update all my apps now -_-
来源:https://stackoverflow.com/questions/34143509/reporting-score-to-gamecenter-in-ios-9-xcode-7-1-1