Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Start(){
- if (GameCenter.isConnected)
- LoginToPlayFabWithGameCenter ();
- else
- LoginToPlayFabWithDevice ();
- }
- void LoginToPlayFabWithGameCenter(){
- //When there is absolutely no account created on PlayFab, this works as expected: A new Account is created linked to the GameCenter.id
- //Now, when there is already an account created linked to the device ID only, a new account won't be created. Instead, PlayFabId returns that account ID; as if they were linked - but they're not
- PlayFabClientAPI.LoginWithGameCenter (
- CreateAccount = true,
- TitleId = PlayFabSettings.TitleId,
- PlayerId = GameCenter.id,
- OnLoginWithGameCenterSuccess, OnLoginWithGameCenterError
- );
- }
- void OnLoginWithGameCenterSuccess(LoginResult result){
- Debug.Log (result.PlayFabId);
- LinkDeviceID ();
- }
- void LinkDeviceID(){
- //This returns successfully, but the link between this device and the GameCenter account is not shown in the Game Manager
- PlayFabClientAPI.LinkIOSDeviceID(
- DeviceId = SystemInfo.deviceUniqueIdentifier,
- DeviceModel = SystemInfo.deviceModel,
- OS = SystemInfo.operatingSystem,
- ForceLink = true,
- OnLinkDeviceIdSuccessful, OnLinkDeviceIdError
- );
- }
- void LoginToPlayFabWithDevice(){
- //Exactly the same behaviour as with LoginToPlayFabWithGameCenter
- //When there is absolutely no account created on PlayFab, this works as expected: A new Account is created linked to the DeviceId
- //Now, when there is already an account created linked to the GameCenter only, a new account won't be created. Instead, PlayFabId returns that account ID; as if they were linked - but they're not
- PlayFabClientAPI.LoginWithIOSDeviceID(
- CreateAccount = true,
- TitleId = PlayFabSettings.TitleId,
- DeviceId = SystemInfo.deviceUniqueIdentifier,
- DeviceModel = SystemInfo.deviceModel,
- OS = SystemInfo.operatingSystem,
- OnLoginWithDeviceIdSuccess, OnLoginWithDeviceIDError
- );
- }
- void OnLoginWithDeviceIdSuccess(LoginResult result){
- Debug.Log (result.PlayFabId);
- StartCoroutine (LoginToGameCenter ());
- }
- IEnumerator LoginToGameCenter(){
- while (true) {
- if (GameCenter.isConnected) {
- LoginToPlayFabWithGameCenter2 ();
- break;
- }
- WaitForSeconds (x);
- }
- }
- //=====Code repeated just to ilustrate the different paths=====
- void LoginToPlayFabWithGameCenter2(){
- //With CreateAccount being false and no account existing linked to GameCenter, this should return an error. But it does not
- //Instead, it logs me in to the same account I am already logged in: The one linked to the device ID only
- PlayFabClientAPI.LoginWithGameCenter (
- CreateAccount = false,
- TitleId = PlayFabSettings.TitleId,
- PlayerId = GameCenter.id,
- OnLoginWithGameCenterSuccess2, OnLoginWithGameCenterError
- );
- }
- void OnLoginWithGameCenterSuccess2(LoginResult result){
- Debug.Log (result.PlayFabId);
- LinkDeviceID2 ();
- }
- void LinkDeviceID2(){
- //This call would only make sense if an actual account had been created in the first place, but it was not.
- //That is why I try to link this GameCenter account to the deviceID account I'm logged in
- PlayFabClientAPI.LinkIOSDeviceID(
- DeviceId = SystemInfo.deviceUniqueIdentifier,
- DeviceModel = SystemInfo.deviceModel,
- OS = SystemInfo.operatingSystem,
- ForceLink = true,
- OnLinkDeviceIdSuccessful, OnLinkDeviceIdError
- );
- LinkGameCenterID ();
- }
- void LinkGameCenterID(){
- //Again, this returns successfully, but the link is not shown in the Game Manager
- PlayFabClientAPI.LinkGameCenterAccount (
- GameCenterId = GameCenter.id
- , OnLinkGameCenterSuccessful, OnLinkGameServiceError);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement