我已經設法讓我的遊戲在啓動時將玩家簽名到遊戲中心,但是當達到高分時,它會將其保存在遊戲中而不是發送到遊戲中心。只要我把遊戲將不會向遊戲中心發送高分
[self reportScore];
它似乎使模擬器崩潰,我重視我的看法Controller.m或者文件,如果你能幫助我的方法,使我的遊戲發送高分到遊戲中心,這樣我可以移動開始發佈排行榜以在應用中顯示排行榜。我順便說一句http://www.appcoda.com/ios-game-kit-framework/
#import "ViewController.h"
#import <GameKit/GameKit.h>
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface ViewController()
@property (nonatomic, strong) NSString *leaderboardIdentifier;
@property (nonatomic,assign) BOOL gameCenterEnabled;
-(void)authenticateLocalPlayer;
-(void)reportScore;
@end
@implementation ViewController
-(void)reportScore{
GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier];
score.value = HighScoreNumber;
[GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
}];
}
-(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;
// Get the default leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
} else {
_leaderboardIdentifier = leaderboardIdentifier;
}
}];
} else {
_gameCenterEnabled = NO;
}
}
};
}
- (void)viewDidLoad
{
[self authenticateLocalPlayer];
HighScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey:@"HighScoreSaved"];
HighScore.text = [NSString stringWithFormat:@"High Score: %li", (long)HighScoreNumber];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark iAd Delegate Methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
@end
您可以嘗試手動設置leaderboardIdentifier而無需查詢GKLocalPlayer並查看是否修復了此問題? –
沒有運氣,我是一個初學xcode,所以會很高興指向正確的方向,我可以學習如何在我的應用程序中實現遊戲中心。我只需要已經保存的遊戲中的高分被髮送到我在itunes中創建的遊戲中心排行榜連接 – uz7