Я пытаюсь реализовать в обновлении приложения в моей игре Unity. мой менеджер по обновлению приложений. Я написал код после прочтения Google Doc, но есть много вещей неясно, поэтому я использовал чат GPT, но все же что -то не так. /> < /p>
my code: < /p>
using System.Collections;
using UnityEngine;
using Google.Play.AppUpdate;
using Google.Play.Common;
using UnityEngine.UI;
public class InAppUpdate : MonoBehaviour
{
private AppUpdateManager appUpdateManager;
// The result from checking for an update, contains information about available updates.
private AppUpdateInfo appUpdateInfoResult;
void Start()
{
// Initialize the AppUpdateManager.
appUpdateManager = new AppUpdateManager();
// Start checking for updates immediately.
StartCoroutine(CheckForUpdate());
}
IEnumerator CheckForUpdate()
{
// Creates a PlayAsyncOperation to check for update info.
PlayAsyncOperation appUpdateInfoOperation =
appUpdateManager.GetAppUpdateInfo();
// Wait until the operation is done.
yield return appUpdateInfoOperation;
// If the operation encounters an error, log it and return.
if (appUpdateInfoOperation.Error != AppUpdateErrorCode.NoError)
{
Debug.LogError("Error checking for update: " + appUpdateInfoOperation.Error);
yield break;
}
// Get the AppUpdateInfo result.
appUpdateInfoResult = appUpdateInfoOperation.GetResult();
// Check if an update is available and if a flexible update is allowed.
if (appUpdateInfoResult.UpdateAvailability == UpdateAvailability.UpdateAvailable)
{
if (appUpdateInfoResult.IsUpdateTypeAllowed(AppUpdateOptions.ImmediateAppUpdateOptions()))
{
StartCoroutine(StartFlexibleUpdate());
}
}
else
{
Debug.LogError("Update is not available");
}
}
IEnumerator StartFlexibleUpdate()
{
// Define app update options for a flexible update.
var appUpdateOptions = AppUpdateOptions.FlexibleAppUpdateOptions();
// Creates an AppUpdateRequest to monitor the update flow.
var startUpdateRequest = appUpdateManager.StartUpdate(appUpdateInfoResult, appUpdateOptions);
// Loop while the update is not yet done.
while (!startUpdateRequest.IsDone)
{
// For flexible flow, the user can continue to use the app while
// the update downloads in the background.
// No UI elements here, as requested.
yield return null;
}
// Once IsDone, check for errors from the StartUpdate operation.
if (startUpdateRequest.Error != AppUpdateErrorCode.NoError)
{
Debug.LogError("Error starting flexible update: " + startUpdateRequest.Error);
yield break;
}
// After the StartUpdate operation is done, re-fetch AppUpdateInfo to get the latest InstallStatus.
var updatedAppUpdateInfoOperation = appUpdateManager.GetAppUpdateInfo();
yield return updatedAppUpdateInfoOperation;
if (updatedAppUpdateInfoOperation.Error != AppUpdateErrorCode.NoError)
{
Debug.LogError("Error re-fetching update info after download: " + updatedAppUpdateInfoOperation.Error);
yield break;
}
AppUpdateInfo updatedAppUpdateInfo = updatedAppUpdateInfoOperation.GetResult();
// Check if the download completed successfully using the updated InstallStatus.
if (updatedAppUpdateInfo.AppUpdateStatus == AppUpdateStatus.Downloaded)
{
// Downloaded successfully, proceed to complete the update.
StartCoroutine(CompleteFlexibleUpdate());
}
else
{
// Handle other download statuses if necessary (e.g., pending, failed).
// This might occur if the download didn't complete for some reason even after IsDone.
Debug.LogWarning("Flexible update install status after download: " + updatedAppUpdateInfo.AppUpdateStatus);
}
}
IEnumerator CompleteFlexibleUpdate()
{
// Request the app update to be installed.
var result = appUpdateManager.CompleteUpdate();
yield return result;
// This line should typically not be reached if the update is successful,
// as the app will restart. If it is reached, an error occurred.
if (result.Error != AppUpdateErrorCode.NoError)
{
Debug.LogError("Error completing flexible update: " + result.Error);
}
}
}
< /code>
Я следую всем, что загружается на треках тестирования и увеличивает код версии. Мое устройство уже в тестировании электронных писем. но каким -то образом исправил это, добавив в основной шаблон.
В настоящее время я очень расстроен, загружая новые версии снова и снова.>
Подробнее здесь: https://stackoverflow.com/questions/797 ... utton-in-u
В обновлении приложения ошибка бросания «Пользователь отменен», когда я нажимаю кнопку «Обновление» в приглашении обновл ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение