1

I have an 'endless' game, where the user has to get as high a score as possible. I have made some achievements, for when they reach 30, 60, 90 points, etc. However, when the user reaches those scores, no banner is shown to say that they have completed the achievement, nor is it shown as completed in Game Center.

How do I do this?

This is my code:

func checkAchievements() {
    var identifier : String? = nil
    var percentComplete : Double = 0
    switch(score)
    {
    case 30:
        identifier = "30"
        percentComplete = 100.0
    case 60:
        identifier = "60"
        percentComplete = 100.0
    case 90:
        identifier = "90"
        percentComplete = 100.0
    case 120:
        identifier = "120"
        percentComplete = 100.0
    case 150:
        identifier = "150"
        percentComplete = 100.0
    default:
        identifier = nil
    }
    if identifier != nil {
        let achievement = GKAchievement(identifier: identifier)
        achievement.showsCompletionBanner = true
        achievement.percentComplete = percentComplete
    }
}
user2397282
  • 3,798
  • 15
  • 48
  • 94

1 Answers1

4

I have never used the GK module but while you have instantiated a GKAchievement object, I don't see your call to report/record it with Game Center. Where is achievement.reportAchievementWithCompletionHandler: ?

Price Ringo
  • 3,424
  • 1
  • 19
  • 33
  • Xcode doesn't seem to recognise `reportAchievementWithCompletionHandler:`. I type in `achievement.` and begin typing `reportAchievementWithCompletionHandler:`, but it doesn't seem to be there???? – user2397282 Sep 10 '14 at 12:41
  • The instance method is deprecated in iOS7. Looks like you should use the *class* method reportAchievements:withCompletionHandler: and pass your achievement object in the first parameter (as an array of one item, by the looks of it, if you've only got one to report.) Perhaps try `GKAchievement.reportAchievements([achievement], withCompletionHandler: nil)`? – Matt Gibson Sep 10 '14 at 12:44