我正在阅读有关应用中心应用内更新的文档。我想尝试一下,这样每次发布我的应用程序时,我都不需要卸载我的应用程序并每次都安装新版本。文档中有一个示例代码,但我不知道将它放在哪里或它是如何工作的,文档不清楚。下面的代码是文档中的示例代码。我的问题是如何为我的应用实施应用内更新?
https://docs.microsoft.com/en-us/appcenter/sdk/distribute/xamarin
bool OnReleaseAvailable(ReleaseDetails releaseDetails)
{
// Look at releaseDetails public properties to get version information, release notes text or release notes URL
string versionName = releaseDetails.ShortVersion;
string versionCodeOrBuildNumber = releaseDetails.Version;
string releaseNotes = releaseDetails.ReleaseNotes;
Uri releaseNotesUrl = releaseDetails.ReleaseNotesUrl;
// custom dialog
var title = "Version " + versionName + " available!";
Task answer;
// On mandatory update, user cannot postpone
if (releaseDetails.MandatoryUpdate)
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install");
}
else
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install", "Maybe tomorrow...");
}
answer.ContinueWith((task) =>
{
// If mandatory or if answer was positive
if (releaseDetails.MandatoryUpdate || (task as Task<bool>).Result)
{
// Notify SDK that user selected update
Distribute.NotifyUpdateAction(UpdateAction.Update);
}
else
{
// Notify SDK that user selected postpone (for 1 day)
// Note that this method call is ignored by the SDK if the update is mandatory
Distribute.NotifyUpdateAction(UpdateAction.Postpone);
}
});
// Return true if you are using your own dialog, false otherwise
return true;
}