不在游戏中心提交分数
我想在我的应用程序中输入游戏中心 所以我创建了新项目“gamecenter”来测试游戏中心 我引用了“http://www.youtube.com/watch?v=9avpP0hYwik”视频。但 我使用 xcode 4.2,所以删除“autorelease”
应用程序未在 gamecenterhelp 上提交分数 :-( 我的代码是
viewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UILabel *scoreText;
int *scoreInt;
}
-(IBAction)subScore:(id)sender;
-(IBAction)showLeader:(id)sender;
-(IBAction)addScore:(id)sender;
@end
ViewController.m
#import "ViewController.h"
#import <Gamekit/Gamekit.h>
@implementation ViewController
-(IBAction)subScore:(id)sender
{
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"1234567"];
scoreReporter.value = scoreInt;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
NSLog(@"failed");
}
else
{
NSLog(@"Succeeded");
}
}];
}
-(IBAction)showLeader:(id)sender
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
}
-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)addScore:(id)sender
{
scoreInt +=1;
NSString *clicks = [NSString stringWithFormat:@"%d", scoreInt];
scoreText.text = clicks;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil)
{
NSLog(@"Authentication Successful!");
}
else
{
NSLog(@"Authentication Failed!");
}
}];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
i want input gamecenter in my app
so i make new project "gamecenter" for test gamecenter
i referenced "http://www.youtube.com/watch?v=9avpP0hYwik" video. but
I use xcode 4.2 so delete of "autorelease"
app does not submit the score at gamecenterhelp plz :-(
my code is
viewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UILabel *scoreText;
int *scoreInt;
}
-(IBAction)subScore:(id)sender;
-(IBAction)showLeader:(id)sender;
-(IBAction)addScore:(id)sender;
@end
ViewController.m
#import "ViewController.h"
#import <Gamekit/Gamekit.h>
@implementation ViewController
-(IBAction)subScore:(id)sender
{
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"1234567"];
scoreReporter.value = scoreInt;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
NSLog(@"failed");
}
else
{
NSLog(@"Succeeded");
}
}];
}
-(IBAction)showLeader:(id)sender
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
}
-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)addScore:(id)sender
{
scoreInt +=1;
NSString *clicks = [NSString stringWithFormat:@"%d", scoreInt];
scoreText.text = clicks;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil)
{
NSLog(@"Authentication Successful!");
}
else
{
NSLog(@"Authentication Failed!");
}
}];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定您的排行榜类别 ID 正确吗?
您在请求块中收到任何错误消息吗?
如果您的异步请求块没有得到响应,则意味着游戏中心尚未准备好处理您的请求。如果您刚刚创建排行榜,则需要等待几个小时。
Are you sure your leaderboard category id is correct?
Do you get any error messages in your request blocks?
If you get no response to your asynchronous request blocks, it means gamecenter is not ready to handle your request. You need to wait for a few hours if you just created the leaderboard.