[英]unable to update gamecenter high score
我正在尝试使用以下代码更新游戏中心排行榜高分
- (void) reportScore: (int64_t) score forLeaderboardID: (NSString*) identifier
{
if([GKLocalPlayer localPlayer].authenticated == YES)
{
NSLog(@"%@",[[GKLocalPlayer localPlayer] playerID]);
NSString *pId=[[GKLocalPlayer localPlayer] playerID];
NSString* PlayerId = [NSString stringWithFormat: @"%@",pId];
NSString *alias = [GKLocalPlayer localPlayer].alias;
NSString *name = [GKLocalPlayer localPlayer].displayName;
NSLog(@"%@",PlayerId);
NSLog(@"%@",alias);
NSLog(@"%@",name);
NSArray *playerArray=[NSArray arrayWithObject: PlayerId];
NSLog(@"%@",[playerArray objectAtIndex:0]);
NSString *String = [[NSString stringWithString:[playerArray objectAtIndex:0]] stringByReplacingOccurrencesOfString:@"G:" withString:@""];
GKPlayer* player= NULL;
GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier: identifier];
// GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier:identifier player:String];
scoreReporter.value = score;
// scoreReporter.context = 0;
NSArray *scores = @[scoreReporter];
[GKScore reportScores:scores withCompletionHandler:^(NSError *error) {
//Do something interesting here.
[[[[UIAlertView alloc] initWithTitle: @"GameCenter" message: @"Score Submitted Successfully" delegate: NULL cancelButtonTitle: @"OK" otherButtonTitles: NULL] autorelease] show];
}];
}
}
我可以在iTunes上创建排行榜后第一次发布分数,但是只有在提交分数后第一次才能发布分数。
我正在使用上面第一次起作用的代码,任何人都可以告诉我如何在任何帮助或代码段很棒的情况下更新玩家的得分。 提前致谢
该代码可能正在工作。 您应该尝试通过NSNotificationCenter调用函数。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reportScore:)
name:@"ReportScore"
object:nil];
-(void)reportScore:(NSNotification *)notification;
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.