我想在我的应用中输入游戏中心
所以我为测试游戏中心制作新项目“gamecenter”
我引用了“http://www.youtube.com/watch?v=9avpP0hYwik”视频。但
我使用xcode 4.2删除“autorelease”
应用程序不会在gamecenterhelp plz上提交分数:-(
我的代码是
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
答案 0 :(得分:0)
您确定您的排行榜类别ID是否正确?
您的请求块中是否收到任何错误消息?
如果您对异步请求块没有响应,则表示gamecenter尚未准备好处理您的请求。如果您刚刚创建了排行榜,则需要等待几个小时。