Authenticating the player's Game Center account

As soon as our app starts, we will check if the player is already logged in to their Game Center account. If not, we will give them a chance to log in. Later, when we want to submit high scores or achievements, we can use the authentication information we gathered when the app launched, instead of interrupting their gaming session to collect their Game Center information.

Follow these steps to authenticate the player's Game Center account when the app starts:

  1. We will be working in the GameViewController class, so open GameViewController.swift in Xcode.
  2. Add a new import statement at the top of the file so we can use the GameKit framework:
    import GameKit
  3. In the GameViewController class, add a new function ...

Get Game Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.