Table of Contents

LoginWithGameCenter

Methods
public static LoginOperation LoginWithGameCenter(GameCenterCredentials credentials, CancellationToken cancellationToken = default)

Login to coherence Cloud using a Game Center account.

Parameters
Type Name Description
GameCenterCredentials credentials

The credentials GameKit returned.

CancellationToken cancellationToken

Used to cancel the operation.

Returns
Type Description
LoginOperation

The status of the asynchronous login operation.

Remarks

'Game Center Auth Enabled' must be ticked, and BundleId must be listed among the allowed bundle identifiers, in Project Settings on your Online Dashboard for this authentication method to be usable.

The credentials are the output of GameKit's fetchItems(forIdentityVerificationSignature:), which the title obtains itself — coherence never calls GameKit. coherence therefore cannot validate them, and two mistakes are only catchable on the calling side:

Pass GKLocalPlayer.teamPlayerID, not gamePlayerID. Apple's signature only attests the teamPlayerID, and it is the identifier flavor the Game Center friends API returns, so anything else is rejected as invalid credentials.

Only log in when GKPlayer.scopedIDsArePersistent() is true. When it is false — for guest players and some identity-less states — GameKit returns session-scoped identifiers that change every session, so every login would silently create a fresh, orphaned player account. The signature still verifies, so neither coherence nor the backend can detect this; the check on the calling side is the only guard.

Examples
using System.Threading.Tasks;
using Coherence.Cloud;
using UnityEngine;

class LoginWithGameCenter : MonoBehaviour
{
    // The credentials come from GameKit's fetchItems(forIdentityVerificationSignature:), which the
    // title fetches itself. Pass GKLocalPlayer.teamPlayerID (not gamePlayerID), and only call this
    // when GKPlayer.scopedIDsArePersistent() is true.
    public async Task<PlayerAccount> Login(string teamPlayerId, string bundleId, string publicKeyUrl,
        byte[] signature, byte[] salt, ulong timestamp)
    {
        var credentials = new GameCenterCredentials(teamPlayerId, bundleId, publicKeyUrl, signature, salt, timestamp);
        PlayerAccount playerAccount = await CoherenceCloud.LoginWithGameCenter(credentials);
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}