GameCenter 未注册分数
Posted
技术标签:
【中文标题】GameCenter 未注册分数【英文标题】:Score is not being registered by GameCenter 【发布时间】:2014-03-04 19:23:52 【问题描述】:游戏已开启,已注册到沙盒,但在 GameCenter 应用上看不到注册数据的痕迹。
该游戏尚未在 AppStore 上架,但我可以在 GameCenter App 上看到该游戏。
过程很简单。我设置了一个 GameKitHelper,看起来它做的事情是正确的。
请看一下:
GameKitHelper.h
// Include the GameKit framework
#import <GameKit/GameKit.h>
// Protocol to notify external
// objects when Game Center events occur or
// when Game Center async tasks are completed
@protocol GameKitHelperProtocol<NSObject>
-(void) onScoresSubmitted:(bool)success;
@end
@interface GameKitHelper : NSObject
@property (nonatomic, assign)
id<GameKitHelperProtocol> delegate;
// This property holds the last known error
// that occured while using the Game Center API's
@property (nonatomic, readonly) NSError* lastError;
+ (id) sharedGameKitHelper;
// Player authentication, info
-(void) authenticateLocalPlayer;
// Scores
-(void) submitScore:(int64_t)score
category:(NSString*)category;
@end
GameKitHelper.m
#import "GameKitHelper.h"
@interface GameKitHelper ()
<GKGameCenterControllerDelegate>
BOOL _gameCenterFeaturesEnabled;
@end
@implementation GameKitHelper
-(void) submitScore:(int64_t)score
category:(NSString*)category
//1: Check if Game Center
// features are enabled
if (!_gameCenterFeaturesEnabled)
CCLOG(@"Player not authenticated");
return;
//2: Create a GKScore object
GKScore* gkScore =
[[GKScore alloc]
initWithCategory:category];
//3: Set the score value
gkScore.value = score;
//4: Send the score to Game Center
[gkScore reportScoreWithCompletionHandler:
^(NSError* error)
[self setLastError:error];
BOOL success = (error == nil);
if ([_delegate
respondsToSelector:
@selector(onScoresSubmitted:)])
[_delegate onScoresSubmitted:success];
];
#pragma mark Singleton stuff
+(id) sharedGameKitHelper
static GameKitHelper *sharedGameKitHelper;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
sharedGameKitHelper =
[[GameKitHelper alloc] init];
);
return sharedGameKitHelper;
#pragma mark Player Authentication
-(void) authenticateLocalPlayer
GKLocalPlayer* localPlayer =
[GKLocalPlayer localPlayer];
localPlayer.authenticateHandler =
^(UIViewController *viewController,
NSError *error)
[self setLastError:error];
if ([CCDirector sharedDirector].isPaused)
[[CCDirector sharedDirector] resume];
if (localPlayer.authenticated)
_gameCenterFeaturesEnabled = YES;
else if(viewController)
[[CCDirector sharedDirector] pause];
[self presentViewController:viewController];
else
_gameCenterFeaturesEnabled = NO;
;
#pragma mark Property setters
-(void) setLastError:(NSError*)error
_lastError = [error copy];
if (_lastError)
NSLog(@"GameKitHelper ERROR: %@", [[_lastError userInfo]
description]);
#pragma mark UIViewController stuff
-(UIViewController*) getRootViewController
return [UIApplication
sharedApplication].keyWindow.rootViewController;
-(void)presentViewController:(UIViewController*)vc
UIViewController* rootVC = [self getRootViewController];
[rootVC presentViewController:vc animated:YES
completion:nil];
@end
首先我调用如下方法进行玩家的认证:
[[GameKitHelper sharedGameKitHelper]
authenticateLocalPlayer];
然后,当关卡完成时,调用第二个方法:
[[GameKitHelper sharedGameKitHelper]
submitScore:(int64_t)numberMoves
category:kMovesLevel1LeaderboardCategory];
排行榜 ID 等于 iTunesConnect。这段代码是我从http://www.raywenderlich.com/23189/whats-new-with-game-center-in-ios-6 得到的,它是针对 6.0 的。但到目前为止我还没有看到有什么大不了的。
我错过了什么? 谢谢!
【问题讨论】:
是的,我已经等了超过 24 小时。有任何想法吗?谢谢! 【参考方案1】:您还记得在 iTunes Connect 中启用排行榜吗?
对于相关应用:
-
点击查看详情 --> 滚动到底部 --> 点击Game Center 开关(在禁用/启用之间切换)。
添加您要使用的排行榜。
【讨论】:
以上是关于GameCenter 未注册分数的主要内容,如果未能解决你的问题,请参考以下文章