UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

GameKit achievement notifications not showing up even though they were working before?

Forums > Swift

Hi all,

A few days ago I got Game Center notifications working for my achievements in my game, they suddenly stopepd working. All I did was re-organise the code, and the achievements are going through to Game Center when you earn them. I cannot think of why my submitAchievements() function in my GameModel() could be wrong, but I'll paste it here:

 func calcAchievements(score: Int, claw: Bool) {
            GKAchievement.loadAchievements(completionHandler: { (achievements: [GKAchievement]?, error: Error?) in
                let fifteenID = "15"
                var fifteenAchievement: GKAchievement? = nil

                // Find an existing achievement.
                fifteenAchievement = achievements?.first(where: { $0.identifier == fifteenID})

                // Otherwise, create a new achievement.
                if fifteenAchievement == nil {
                    fifteenAchievement = GKAchievement(identifier: fifteenID)
                }

                if score == 15 {
                    fifteenAchievement?.showsCompletionBanner = true
                    fifteenAchievement?.percentComplete = 100
                }

                let thirtyID = "30"
                var thirtyAchievement: GKAchievement? = nil

                thirtyAchievement = achievements?.first(where: { $0.identifier == thirtyID})

                if thirtyAchievement == nil {
                    thirtyAchievement = GKAchievement(identifier: thirtyID)
                }

                if score == 30 {
                    thirtyAchievement?.showsCompletionBanner = true
                    thirtyAchievement?.percentComplete = 100
                }

                let fiftyID = "50"
                var fiftyAchievement: GKAchievement? = nil

                fiftyAchievement = achievements?.first(where: { $0.identifier == fiftyID})

                if fiftyAchievement == nil {
                    fiftyAchievement = GKAchievement(identifier: fiftyID)
                }

                if score == 50 {
                    fiftyAchievement?.showsCompletionBanner = true
                    fiftyAchievement?.percentComplete = 100
                }

                let hundredID = "100"
                var hundredAchievement: GKAchievement? = nil

                hundredAchievement = achievements?.first(where: { $0.identifier == hundredID})

                if hundredAchievement == nil {
                    hundredAchievement = GKAchievement(identifier: hundredID)
                }

                if score == 100 {
                    hundredAchievement?.showsCompletionBanner = true
                    hundredAchievement?.percentComplete = 100
                }

                let negativeID = "1"
                var negativeAchievement: GKAchievement? = nil

                negativeAchievement = achievements?.first(where: { $0.identifier == negativeID})

                if negativeAchievement == nil {
                    negativeAchievement = GKAchievement(identifier: negativeID)
                }

                if score < 0 {
                    negativeAchievement?.showsCompletionBanner = true
                    negativeAchievement?.percentComplete = 100
                }

                let clawID = "69"
                var clawAchievement: GKAchievement? = nil

                clawAchievement = achievements?.first(where: { $0.identifier == clawID})

                if clawAchievement == nil {
                    clawAchievement = GKAchievement(identifier: clawID)
                }

                if claw {
                    clawAchievement?.showsCompletionBanner = true
                    clawAchievement?.percentComplete = 100
                }

                if error != nil {
                    print("Error: \(String(describing: error))")
                }

                // Insert code to report the percentage.

                let achievementsToReport: [GKAchievement] = [fifteenAchievement!, thirtyAchievement!, fiftyAchievement!, hundredAchievement!, clawAchievement!, negativeAchievement!]

                GKAchievement.report(achievementsToReport, withCompletionHandler: {(error: Error?) in
                    if error != nil {
                        print("Error: \(String(describing: error))")
                    }
                })
            })
        }

All the showCompletionBanner flags for each achievement is true, so I have no idea what's going on. I've reset the achievements and tested this multiple times, so I'm sure the achievements aren't showing up because they are already earned. If you are interested, here is my git repo: https://github.com/aabagdi/CursedSnake

Thanks so much for any help!!

3      

Hi @Vendetagainst. Did you ever solve this?

I have the same issue. I can set achievements, but the banner never shows for the achievement. I've tried just about everything.

Jamie

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.