iOS6中的游戏中心崩溃

时间:2013-01-11 13:02:12

标签: iphone objective-c ios5 ios6 game-center

我的游戏在iOS5中已经完美运行了一年。在更新它以使用iOS6后,它现在在尝试在Game Center中发送分数时崩溃。它在代码

中的reportScoreWithCompletionHandler行崩溃
- (void)sendScore:(GKScore *)score {
    [score reportScoreWithCompletionHandler:^(NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^(void)
                       {
                           if (error == NULL) {
                               NSLog(@"Successfully sent score!");
                               [scoresToReport removeObject:score];                
                           } else {
                               NSLog(@"Score failed to send... will try again later.  Reason: %@", error.localizedDescription);                
                           }
                       });
    }];
}

我在这里做错了什么?

更新

看了一下似乎authenticateWithCompletionHandler可能也存在问题...我的代码就在下面..如果这是责备我怎么能更新它以便它起作用?

- (void)authenticateLocalUser { 

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {     
        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];        
    } else {
        NSLog(@"Already authenticated!");
    }
}

1 个答案:

答案 0 :(得分:1)

我找到了解决方案here

您似乎必须创建乐谱的副本并提交副本。只有在重新发送已保存的分数时才会发生这种情况。这可能是因为它试图阻止您从排行榜发送GKScore

// Pull the score value and category from the passed in score
int scoreValue = score.value;
NSString*scoreCategory = score.category;

// Create a new temporary score with these values
GKScore *toReport = [[[GKScore alloc]
initWithCategory:scoreCategory] autorelease];
toReport.value = scoreValue;