Question

this is a likely silly question. But I added Game Center to my app and now I want to add achievements, too. So I created a test achievement on itunesconnect and copied this method:

    - (void) 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).
    }
   }];
    } }

But what do I have to do now. Where do I have to write the code that says that the achievement is reached? Where do I have to write the code that says that the achievement is reached by doing this?

Was it helpful?

Solution

If you're asking how to present the achievement to the user (i.e. "Achievement Earned!"), it's entirely up to you. Your game must implement the visuals in whatever way fits in the best.

If you just need a quick and easy achievement display, try this:

http://typeoneerror.com/blog/post/game-center-achievement-notification

OTHER TIPS

Use GKAchievementin instance property showsCompletionBanner to show the system achievement banner to the user.

A Boolean value that states whether a banner is displayed when the achievement is completed.

Swift 4

let achievement = GKAchievement(identifier: achievementId)
achievement.percentComplete = 100.0
achievement.showsCompletionBanner = true

Objc

GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier: achievementId];
[achievement setPercentComplete:100.0];
[achievement setShowsCompletionBanner:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top