我的游戏不会出现在游戏中心,我整天都在想办法解决这个问题,这让我发疯了。我想将带有对象键“分数”的字符串保存到排行榜上。我一定遗漏了一些非常明显的东西,但我不知道。很抱歉打扰你们,但这只是让我生气,哈哈。捆绑包 id 是 moocowcurtis,我确实把它放在了 info.plist
游戏中心管理器.h
#import <Foundation/Foundation.h>
@class GKLeaderboard, GKAchievement, GKPlayer;
@protocol GameCenterManagerDelegate <NSObject>
@optional
- (void) processGameCenterAuth: (NSError*) error;
- (void) scoreReported: (NSError*) error;
- (void) reloadScoresComplete: (GKLeaderboard*) leaderBoard error: (NSError*) error;
- (void) achievementSubmitted: (GKAchievement*) ach error:(NSError*) error;
- (void) achievementResetResult: (NSError*) error;
- (void) mappedPlayerIDToPlayer: (GKPlayer*) player error: (NSError*) error;
@end
@interface GameCenterManager : NSObject
{
NSMutableDictionary* earnedAchievementCache;
id <GameCenterManagerDelegate, NSObject> delegate;
}
//This property must be attomic to ensure that the cache is always in a viable state...
@property (retain) NSMutableDictionary* earnedAchievementCache;
@property (nonatomic, assign) id <GameCenterManagerDelegate> delegate;
+ (BOOL) isGameCenterAvailable;
- (void) authenticateLocalUser;
- (void) reportScore: (int64_t) score forCategory: (NSString*) category;
- (void) reloadHighScoresForCategory: (NSString*) category;
- (void) submitAchievement: (NSString*) identifier percentComplete: (double) percentComplete;
- (void) resetAchievements;
- (void) mapPlayerIDtoPlayer: (NSString*) playerID;
@end
排行榜.m 文件
#import "leaderboard.h"
#import "GameCenterManager.h"
@implementation leaderboard
-(id) init
{
[[GameCenterManager sharedGameCenterObject] reportScore:score forCategory: kLeaderboardID];
int highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"score"] intValue];
return self;
}
-(void)displayLeaderboard
{
GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.leaderboardDelegate = self;
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController presentModalViewController:leaderboardViewController animated:YES];
}
#pragma mark GameKit delegate
-(void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{ [super dealloc];
}
@end
排行榜.h
#import "GameCenterManager.h"
@interface leaderboard: CCLayer<GKLeaderboardViewControllerDelegate>
@end
游戏中心管理器.h
#import <Foundation/Foundation.h>
@class GKLeaderboard, GKAchievement, GKPlayer;
@protocol GameCenterManagerDelegate <NSObject>
@optional
- (void) processGameCenterAuth: (NSError*) error;
- (void) scoreReported: (NSError*) error;
- (void) reloadScoresComplete: (GKLeaderboard*) leaderBoard error: (NSError*) error;
- (void) achievementSubmitted: (GKAchievement*) ach error:(NSError*) error;
- (void) achievementResetResult: (NSError*) error;
- (void) mappedPlayerIDToPlayer: (GKPlayer*) player error: (NSError*) error;
@end
@interface GameCenterManager : NSObject
{
NSMutableDictionary* earnedAchievementCache;
id <GameCenterManagerDelegate, NSObject> delegate;
}
//This property must be attomic to ensure that the cache is always in a viable state...
@property (retain) NSMutableDictionary* earnedAchievementCache;
@property (nonatomic, assign) id <GameCenterManagerDelegate> delegate;
+ (BOOL) isGameCenterAvailable;
- (void) authenticateLocalUser;
- (void) reportScore: (score) forCategory: (NSString*) category;
- (void) reloadHighScoresForCategory: (NSString*) category;
- (void) submitAchievement: (NSString*) identifier percentComplete: (double) percentComplete;
- (void) resetAchievements;
- (void) mapPlayerIDtoPlayer: (NSString*) playerID;
@end
AppSpecificValues.h
#define kEasyLeaderboardID @"com.appledts.EasyTapList"
#define kHardLeaderboardID @"com.appledts.HardTapList"
#define kAwesomeLeaderboardID @"moocowcurtis"