游戏开启,它已注册到Sandbox,但在GameCenter App上看不到注册数据的踪迹。
游戏尚未在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];
LeaderBoard ID等于iTunesConnect。我从http://www.raywenderlich.com/23189/whats-new-with-game-center-in-ios-6得到的这段代码,是6.0的目标。但到目前为止我没有看到任何重大事项。
我错过了什么? 谢谢!
答案 0 :(得分:0)
您还记得在iTunes Connect中启用排行榜吗?
对于有问题的应用: