Beispiel #1
0
        protected virtual async Task SilentlyAuthenticate(Platform platform, System.Action <LoginResult> callback = null)
        {
            PlayFabResult <LoginResult> result = null;

            switch (platform)
            {
            case Platform.Android:
            {
                //Login with the android device ID
                result = await PlayFabClient.LoginWithAndroidDeviceIDAsync(new LoginWithAndroidDeviceIDRequest()
                    {
                        TitleId               = PlayFabSettings.staticSettings.TitleId,
                        AndroidDevice         = CrossDeviceInfo.Current.DeviceName,
                        OS                    = CrossDeviceInfo.Current.Platform.ToString(),
                        AndroidDeviceId       = CrossDeviceInfo.Current.Id,
                        CreateAccount         = true,
                        InfoRequestParameters = this.InfoRequestParams
                    }).ConfigureAwait(false);
            }
            break;

            case Platform.iOS:
            {
                result = await PlayFabClient.LoginWithIOSDeviceIDAsync(new LoginWithIOSDeviceIDRequest()
                    {
                        TitleId               = PlayFabSettings.staticSettings.TitleId,
                        DeviceModel           = CrossDeviceInfo.Current.Model,
                        OS                    = CrossDeviceInfo.Current.Platform.ToString(),
                        DeviceId              = CrossDeviceInfo.Current.Id,
                        CreateAccount         = true,
                        InfoRequestParameters = InfoRequestParams
                    }).ConfigureAwait(false);
            }
            break;

            default:
            {
                result = await PlayFabClient.LoginWithCustomIDAsync(new LoginWithCustomIDRequest()
                    {
                        TitleId               = PlayFabSettings.staticSettings.TitleId,
                        CustomId              = CrossDeviceInfo.Current.Id,
                        CreateAccount         = true,
                        InfoRequestParameters = InfoRequestParams
                    }).ConfigureAwait(false);
            }
            break;
            }

            if (null != result.Error)
            {
                //report errro back to the subscriber
                if (callback == null)
                {
                    Logout();
                    OnPlayFabError?.Invoke(result.Error);
                }
                else
                {
                    //make sure the loop completes, callback with null
                    callback.Invoke(null);
                }
            }
            else
            {
                //Store identity and session
                PlayFabId     = result.Result.PlayFabId;
                SessionTicket = result.Result.SessionTicket;

                //check if we want to get this callback directly or send to event subscribers.
                if (callback == null)
                {
                    //report login result back to the subscriber
                    OnLoginSuccess?.Invoke(result.Result);
                }
                else
                {
                    //report login result back to the caller
                    callback.Invoke(result.Result);
                }
            }
        }