Skip to main content

iOS

The purpose of this article is to describe how to set up Game Center authentication so that your game can be logged in through the Game Center channel using the Player Network login authentication service.

Prerequisites

1. Configure iOS Applications on Apple Developer
1. Create App ID
  1. Register and sign in for an Apple Developer account on the Apple Developer Platform (https://developer.apple.com/account).

  2. Click Account in the top navigation bar and select Identifiers under Certificates, IDs & Profiles.

    Image: Apple Account

  3. Click the blue add icon (+).

    Image: Apple Identifiers

  4. After selecting App IDs, click Continue.

    Image: Apple App ID

  5. After selecting App, click Continue.

    Image: Apple App ID

  6. Enter Description and Bundle ID.

    • Description: The name or description of the game app.
    • Bundle ID: The unique identifier of the game app included in the App ID.

    Image: Apple bundle description

  7. Under Capabilities, select Sign in with Apple and click Continue.

  8. Click Register to create the App ID.

2. Setting up App Store Connect
  1. Log in to [App Store Connect] (https://appstoreconnect.apple.com/).

  2. Select App.

    Image:GameCenter ChooseApp

  3. Click App (+) and select Add App.

    Image: GameCenter AddApp

  4. Create an App Store Connect App based on the Bundle ID obtained in step 1.

    Image:GameCenter iTunes Connect 1

  5. Select Feature > Game Center to enter the Game Center configuration page.

  6. Enable the Game Center feature.

For more information, see:https://developer.apple.com/help/app-store-connect/

the charts (of best-sellers)
  1. Select Game Center in the left navigation bar and on the right side select Add leaderboards to create a new leaderboard or Add an achievement to add an achievement setting.

Image:GameCenter iTunes Connect

  1. Enter details as required.
info

Click on the question mark (**?) icon next to each field entry box. **) icon, a detailed explanation will be given.

  1. Click Storage to save the configured leaderboard.

Image: GameCenter Leaderboard

info

Users can add as many leaderboards as needed.The leaderboard supports multiple languages, each of which must be added separately.Achievement settings are similar to leaderboard settings.

  1. Obtain Player Network Console login account.
  2. Create a new project for your game, or join an existing one.
  3. Download SDK.
  4. Integrate SDK.
  5. Add Game Center as the login authentication method for business in the Player Network console.

Step 1:Configure the SDK for Game Center login

  1. On the Signing & Capabilities page of the target project, the Bundle Identifier must be a registered iOS App app in App Store Connect.
    Otherwise, when users log in to Game Center, they will receive an error message indicating that Game Center is not supported.

  2. On the Signing & Capabilities page of the target project, add + Capability Add Game Center.

info

The system library dependency GameKit.framework is automatically added to the project dependencies in Xcode.

Image:Game Center Xcode

Step 2:Add Game Center login

In versions after iOS 10, Game Center will continue to exist as a service, but there will no longer be a separate Game Center app on users' devices.Users can go to Settings > Game Center to log in and continue using the features.

There are two main scenarios for users to log into Game Center within a game:

  • Already performs background login via Settings > Game Center by logging into:and displaying the Welcome back, xxxx banner.The entire login process will not interrupt the game.

    Image: Game Center login 1

  • Failed Settings > Game Center Login:A Game Center login box will pop up in-game.If a user cancels their login three times, they will not be able to access the Game Center login box within the game and will need to return to Settings > Game Center to manually login to Game Center.

    Image:Game Center login 2

  1. Register login-related callbacks.
// Add callbacks
public void AddAuthObserver()
{
INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
}

// Remove callbacks
public void RemoveAuthObserver()
{
INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
}

// Process the INTLAuthResult callback
public void OnAuthResultEvent(INTLAuthResult AuthResult)
{
Debug.Log($"MethodID: {AuthResult.MethodId}");

string methodTag = "";
switch (AuthResult.MethodId)
{
case (int)INTLMethodID.INTL_AUTH_LOGIN:
methodTag = "Login";
break;
case (int)INTLMethodID.INTL_AUTH_BIND:
methodTag = "Bind";
break;
case (int)INTLMethodID.INTL_AUTH_AUTOLOGIN:
methodTag = "AutoLogin";
break;
case (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO:
methodTag = "QueryUserInfo";
break;
case (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT:
methodTag = "GetAuthResult";
break;
}
}
  1. Call the AutoLogin interface to log in automatically.
INTLAPI.AutoLogin();
  1. If automatic login fails, call the Login interface to let the player log in manually.
INTLAPI.Login(INTLChannel.GameCenter);
  1. Synchronize client authentication status with the game backend and wait for the final verification result.

Step 3: Acceptance testing for login functionality

Search for the keyword "AuthResult" in the Player Network SDK logs to confirm whether the channel name and OpenID are returned correctly.If correct, it means the integration configuration is successful, and login functionality has been successfully added.

If you encounter problems during the integration process, please refer to Frequently Asked Questions.

Player Restrictions

After successfully logging into Game Center, the GKLocalPlayer object will provide restriction status information that the game can use to restrict functionality:

  • isUnderage:Determines if the player is a minor.
  • isMultiplayerGamingRestricted:Determines if the player can join a multiplayer game.
  • isPersonalizedCommunicationRestricted:Determines if the player can use the personalized communication feature on the device.

Game Center Achievements System

The Player Network SDK provides an Achievement module, integrating the Game Center achievement feature on iOS.Games can unlock achievements, increase progress, and display the native achievements interface through this module.

For the design and operation of Game Center achievements, see the Apple official documentation.

Prerequisites

  1. Completed the Game Center configuration outlined in the prerequisite section of this document, and configured achievements in Game Center within App Store Connect.
  2. Before calling the achievement API, the player must be logged in to Game Center; otherwise, the API will return a NEED_LOGIN error via callback.
    • Players can log in directly through the Game Center channel; if the game uses another channel as the primary login method, you can enable the GAMECENTER_ENABLE_GC configuration (disabled by default). The SDK will automatically complete Game Center authorization after the main channel login succeeds.

Register Achievement Callback

Register a callback to receive achievement operation results.

// Add achievement callback
INTLAPI.AddAchievementResultObserver(OnAchievementResult);

// Remove achievement callback
INTLAPI.RemoveAchievementResultObserver(OnAchievementResult);

// Handle achievement result
public void OnAchievementResult(INTLAchievementResult ret)
{
Debug.Log($"Achievement MethodID: {ret.MethodId}, RetCode: {ret.RetCode}, Platform: {ret.Platform}");
}

Unlock Achievement

Unlock a standard achievement by achievement ID.

INTLAPI.UnlockAchievement("GameCenter", "achievement_id_here");

Increment Achievement Progress

For incremental achievements, increase progress by the specified value.

note

progress is a percentage increment (0–100), added to the current progress and capped at 100%.For example, if progress is at 30% and you enter 20, it updates to 50%.

// Increase achievement progress by 20%
INTLAPI.IncrementAchievement("GameCenter", "achievement_id_here", 20);

Show achievements interface

Display the native Game Center achievements interface.After Player closes the interface, a callback will return the result.

INTLAPI.ShowAchievementsUI("GameCenter");

Game Center Leaderboard

The Player Network SDK provides a Leaderboard module, integrating the Game Center leaderboard feature on iOS.Projects can submit scores and display the native leaderboard interface through this module.

For the design and operation of Game Center leaderboards, see the Apple official documentation.

note

On iOS, SubmitScore and ShowLeaderboardUI rely on the new GKLeaderboard interface, requiring iOS 14.0 or above.When called on a device under iOS 14, the interface will return a NOT_SUPPORT error via callback.

Prerequisites

  1. Complete the Game Center configuration in the Prerequisites section, and create the leaderboard in App Store Connect under Game Center. Record the Leaderboard ID.
  2. Before calling the leaderboard API, the player must already be logged into Game Center (same as the Achievement Prerequisites), otherwise the API will return a NEED_LOGIN error via callback.

Register Leaderboard Callback

Register a callback to receive leaderboard operation results.

// Add leaderboard callback
INTLAPI.AddLeaderboardResultObserver(OnLeaderboardResult);

// Remove leaderboard callback
INTLAPI.RemoveLeaderboardResultObserver(OnLeaderboardResult);

// Handle leaderboard result
public void OnLeaderboardResult(INTLLeaderboardResult ret)
{
Debug.Log($"Leaderboard MethodID: {ret.MethodId}, RetCode: {ret.RetCode}, Platform: {ret.Platform}");
}

Submit Score

Submit a score to the specified leaderboard.

INTLAPI.SubmitScore("GameCenter", "leaderboard_id_here", 1000);

Show leaderboard interface

Display the native Game Center leaderboard interface.After Player closes the interface, a callback will return the result.

note

When a specific leaderboard ID is provided in leaderboardId, only that leaderboard is displayed. When an empty string ("") is provided, the full list of leaderboards is displayed.

// Show specific leaderboard
INTLAPI.ShowLeaderboardUI("GameCenter", "leaderboard_id_here");

// Show all leaderboards
INTLAPI.ShowLeaderboardUI("GameCenter", "");