Sending Achievements to GameCenter Problem!
Well, I have already registered a leaderboard and an achievement (just for testing purposes). I use that GameCenterManager.h/.m and AppScoreValue.h
My leaderboard is working normally receives all the scores, puts them in order, but the achievement isn't granted to the player.
I'd like an example showing how to report achievements, I tried this:
My view did load method looks like this:
-(void)viewDidLoad{
[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, 开发者_如何学GoNSError *error) {
if (error != nil)
{
NSLog(@"ACHIEVEMENTS WERE NOT LOADED");
} else {
NSLog(@"ACHIEVEMENTS WERE LOADED");
}
if (achievements != nil)
{
NSLog(@"THERE ARE ACHIVEMENTS");
} else {
NSLog(@"THERE ARE NO ACHIVEMENTS %@", achievements);
}
}];
Here's my achievement reporting method:
- (IBAction)reportAchievementIdentifier:(NSString*)identifier percentComplete:(float) percent {
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];
if (achievement)
{
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError *error)
{
if (error != nil)
{
// Retain the achievement object and try again later (not shown).
}
}];
}
}
When you report an Achievement, you call something like this:
[self reportAchievementIdentifier:@"com.yourapp.yourachievement" percentComplete:100.0];
(You want to replace the identifier with whatever you used for your Game Center identifier.)
I suggest looking at this documentation from Apple. It contains a full fledged tutorial on how to use Achievements in your app.
The basic idea is that your app reports a a percentage of how much your user completed the achievement. Note that achievements don't always propagate immediately.
GKAchievement *achievement =
[[GKAchievement alloc] initWithIdentifier: identifier];
achievement.showsCompletionBanner = YES;
that's it!
精彩评论