iOS 14+
In iOS 14 and above we should use:
/// Class method to submit a single score to multiple leaderboards
/// score - earned by the player
/// context - developer supplied metadata associated with the player's score
/// player - the player for whom this score is being submitted
/// leaderboardIDs - one or more leaderboard IDs defined in App Store Connect
@available(iOS 14.0, *)
open class func submitScore(_ score: Int, context: Int, player: GKPlayer, leaderboardIDs: [String], completionHandler: @escaping (Error?) -> Void)
Here is an example:
GKLeaderboard.submitScore(
score,
context: 0,
player: GKLocalPlayer.local,
leaderboardIDs: ["leaderboardID"]
) { error in
print(error)
}
Async variant
The above API is compatible with Swift 5.5 concurrency. If you want your method to be async just use:
@available(iOS 14.0, *)
open class func submitScore(_ score: Int, context: Int, player: GKPlayer, leaderboardIDs: [String]) async throws
try await GKLeaderboard.submitScore(
score,
context: 0,
player: GKLocalPlayer.local,
leaderboardIDs: ["leaderboardID"]
)