c# – How can I distinguish a participant signed in anonymously from a participant signed in with Apple Signal In?

0
1
c# – How can I distinguish a participant signed in anonymously from a participant signed in with Apple Signal In?


In keeping with the docs, it is advisable do the next:

  • Register Anonymously such as you’re doing

  • Immediate the participant to set off the Apple Sport Middle sign-in and get the ID verification parameters from GameKit. Then, name the LinkWithAppleGameCenterAsync API to hyperlink the participant to the Apple Sport Middle teamPlayerID.

async Activity LinkWithAppleGameCenterAsync(string signature, string teamPlayerId, string   publicKeyURL, string salt, ulong timestamp)
{
    attempt
    {
        await AuthenticationService.Occasion.LinkWithAppleGameCenterAsync(signature, teamPlayerId, publicKeyURL, salt, timestamp);
        Debug.Log("Hyperlink is profitable.");
    }
    catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked)
    {
        // Immediate the participant with an error message.
        Debug.LogError("This person is already linked with one other account. Log in as a substitute.");
    }
    catch (AuthenticationException ex)
    {
        // Examine error code to AuthenticationErrorCodes
        // Notify the participant with the correct error message
        Debug.LogException(ex);
    }
    catch (RequestFailedException ex)
    {
        // Examine error code to CommonErrorCodes
        // Notify the participant with the correct error message
        Debug.LogException(ex);
    }
}

One other factor, there are two kinds of IDs on iOS, the teamPlayerID and the gamePlayerID . You in all probability want to make use of the teamPlayerID for leaderboards. It’s because the gamePlayerID is for safeguarding the participant’s privateness and it will not all the time return the identical worth.

And lastly, to verify if the participant is already signed in utilizing Apple, use the next code

public bool IsLinkedWithApple()
{
    var playerInfo = AuthenticationService.Occasion.PlayerInfo;

    // Test if playerInfo exists and comprises any identities
    if (playerInfo != null && playerInfo.Identities.Rely > 0)
    {
        // Test if any of the linked identities are of sort "apple"
        return playerInfo.Identities.Any(i => i.TypeId.Incorporates("apple"));
    }
    return false; // No participant information or no identities linked
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here