An object that communicates with Game Center about the local player’s progress toward completing an achievement.
- iOS 4.1+
- macOS 10.8+
- tvOS 9.0+
- watchOS 3.0+
Achievements are a great way to provide your players with feedback and a sense of accomplishment. However, you can’t just add an achievement to your game programmatically. There are several steps that you must accomplish to add achievements to your game:
Before you add achievements, add code to authenticate the local player. See Working with Players in Game Center.
Design your game’s achievements. See Designing an Achievement.
Go to App Store Connect and configure the achievements for your game. You provide all of the data needed to display achievements to the player. See Configuring Achievements in iTunes Connect.
Add code to report the local player’s progress to Game Center. By storing the progress on Game Center, you also make the player’s progress visible in the Game Center app. To report the local player’s progress on an achievement, your game updates the
percentproperty of an achievement object and calls the object’s
reportclass method. Use this method when reporting one or multiple achievements.
Achievements: with Completion Handler:
Add code to load the local player’s previous progress on achievements from Game Center. To request the local player’s progress on achievements, call the
loadclass method. Load the local player’s progress shortly after the player is successfully authenticated.
Achievements With Completion Handler:
By default, when an achievement is completed, GameKit displays a notification banner to the player. If your game wants to display its own achievement user interface, you can prevent the banner from being displayed by setting the
shows property of the achievement object to
NO before reporting the player’s progress.
To clear all progress the local player has made on achievements, call the
reset class method.