score submittion failure

2019-08-28 02:49发布

问题:

I am receiving always a Failure in my cocos2d, but when I run this project in my view based application then it will give me success, and the score will easily submitted

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){
    if (error ==nil) {
        NSLog(@"Success");
    } else {
        NSLog(@"Fail");
    }   
}];


GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:@"123"] autorelease];
myScoreValue.value =  lastScore;

[myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
    if(error != nil){
        NSLog(@"Score Submission Failed");
    } else {
        NSLog(@"Score Submitted");
    }

}];

回答1:

Have you added the GameKit framework, and also; where have you placed the code?

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){ if (error ==nil) { NSLog(@"Success"); } else { NSLog(@"Fail"); }

}];

You have to authenticate when the user starts the app, or when the viewDidLoad function is called.

I don't think I really understand what your problem is. What warnings do you geT?



回答2:

I had this error, too. I think it happens when you're logged into a regular gamecenter acct and try to autenticate with an app that needs to be sandboxed. But I'm not sure of that, that's just a guess.

What worked for me was to go and log out with the Game Center app, and then try the app again, and that will login or create a sandboxed user.

Not the most descriptive error message ever though.