我的游戏不会出现在游戏中心,而且我一整天都试图解决这个问题,这让我疯狂。我想将一个带有对象键“score”的字符串保存到排行榜上。我必须遗漏一些非常明显但我不知道的事情。很抱歉打扰你们,但这只是让我发疯了哈哈。 bundle id是moocowcurtis,我把它放在info.plist
中gamecentermanager.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
leaderboard.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
leaderboard.h
#import "GameCenterManager.h"
@interface leaderboard: CCLayer<GKLeaderboardViewControllerDelegate>
@end
GameCenterManager.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"
答案 0 :(得分:0)
你说“我想用对象键”得分“将字符串保存到排行榜上。”
但是在这一行上,得分必须是int64_t而不是字符串:
[[GameCenterManager sharedGameCenterObject] reportScore:score forCategory: kLeaderboardID];