【问题标题】:unable to update gamecenter high score无法更新gamecenter高分
【发布时间】: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


    【解决方案1】:

    它可能正在运行此代码。你应该试试NSNotificationCenter的调用函数。

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reportScore:)
                                                 name:@"ReportScore"
                                               object:nil];
    
    -(void)reportScore:(NSNotification *)notification;
    

    希望对这段代码有帮助。

    【讨论】:

    • 我的问题是如何让玩家 ID 它一直说 null __NSCFString to string 我无法更新同一玩家的分数
    猜你喜欢
    • 2013-06-03
    • 2013-04-12
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 2012-05-03
    相关资源
    最近更新 更多