我正在阅读有关应用程序中心应用内更新的文档。我想尝试一下,以便每次有我的应用程序发布时,都不需要每次都卸载我的应用程序并安装新版本。文档中有一个示例代码,但我不知道在哪里放置它或它如何工作尚不清楚。下面的代码是文档中的示例代码。我的问题是如何为我的应用程序实现应用程序内更新?
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;
}
答案 0 :(得分:0)
您可以通过OnReleaseAvailable
将回调设置为Distribute.ReleaseAvailable
方法
打开MainActivity.cs并在OnCreate()方法内添加Start()调用
Distribute.ReleaseAvailable = OnReleaseAvailable;
AppCenter.Start(...);
打开您的AppDelegate.cs,并在FinishedLaunching()方法内添加Start()调用
Distribute.ReleaseAvailable = OnReleaseAvailable;
AppCenter.Start(...);
re:https://docs.microsoft.com/en-us/appcenter/sdk/distribute/xamarin#2-start-app-center-distribute