iphoneobjective-cnotificationsgame-centerachievements

Game Center iPhone - Load Achievement Progress


I have my app give a notification when a Game Center achievement is achieved/reaches 100%, however it shows the notification every times the user completes it, but I only want it to notify the first time in actually completed.

I found this in the Apple docs: http://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Achievements/Achievements.html#//apple_ref/doc/uid/TP40008304-CH7-SW11

However didn't quite understand how it help fix my issue.

I only want to call this notification once, when the achievement is first achieved. So only show it if its not already achieved.

Edit

I have this to unlock the achievement:

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

And unlock with this:

[self reportAchievementIdentifier:identifier percentComplete:percent];

Then show the notification with this line:

[[GKAchievementHandler defaultHandler] notifyAchievementTitle:@"Title" andMessage:@"Message"];

So do I simply need something like this in that code chunk?

if (achievement.completed != TRUE) {
      [[GKAchievementHandler defaultHandler] notifyAchievementTitle:@"Title" andMessage:@"Message"];
}

Solution

  • There's a "completed"-property in GKAchievement... Try to make a new GKAchievement and check if it's not completed, then unlock it.