【发布时间】:2015-06-07 22:15:01
【问题描述】:
所以我有一个具有Game A 和Game B 的应用程序。
我已经为游戏 A 正确实现了游戏中心(我使用了 AppCoda tutorial,就像目前为止的每款游戏一样)。
现在,如果玩游戏 B,我无法提交分数。我需要将分数提交到在 iTunes Connect 中创建的第二个排行榜。
这是我的 ViewController 的一部分,用于验证用户并使用排行榜等的标识符。
ViewController.h:
-(void)authenticateLocalPlayer{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
}
else{
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterEnabled = YES; //added bool indentier to .h
// Get the default leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
_leaderboardIdentifier = leaderboardIdentifier; //added pointer to NSString to .h
}
}];
}
else{
_gameCenterEnabled = NO;
}
}
};
}
似乎我的游戏 B 视图控制器正在评分/提交就像游戏 A,我想我可以将上面的代码更改为:(以允许第二个标识符):
-(void)authenticateLocalPlayer{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
}
else{
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterEnabled = YES; //added bool indentier to .h
_gameCenterEnabled2 = YES;
// Get the default leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
_leaderboardIdentifier = leaderboardIdentifier; //added pointer to NSString to .h
}
}];
// Get the second leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier2, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
_leaderboardIdentifier2 = leaderboardIdentifier2; //added pointer to NSString to .h
}
}];
}
else{
_gameCenterEnabled = NO;
_gameCenterEnabled2 = NO;
}
}
};
}
但由于某种原因,它不会将分数发送到第二个排行榜,而且我找不到任何关于如何将分数提交到“非默认”排行榜的资源/教程...
【问题讨论】:
标签: ios objective-c game-center