【发布时间】:2017-10-30 15:10:56
【问题描述】:
我正在尝试更新游戏中心排行榜高分。
我正在使用以下代码:
- (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 上创建排行榜后第一次发布分数,但只有第一次提交分数后我无法更新自己的分数。
我研究了我需要使用玩家ID,没有玩家ID我无法更新玩家分数。
我正在使用第一次工作的上述代码。 如何更新玩家分数?
【问题讨论】:
标签: ios objective-c cocos2d-iphone game-center