xamarin - App Center Distribute – Xamarin Forms 的应用内更新
问题描述
我正在阅读有关应用中心应用内更新的文档。我想尝试一下,这样每次发布我的应用程序时,我都不需要卸载我的应用程序并每次都安装新版本。文档中有一个示例代码,但我不知道将它放在哪里或它是如何工作的,文档不清楚。下面的代码是文档中的示例代码。我的问题是如何为我的应用实施应用内更新?
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;
}
解决方案
安卓:
您通过以下方式将回调设置为您的OnReleaseAvailable
方法Distribute.ReleaseAvailable
打开 MainActivity.cs 并在 OnCreate() 方法中添加 Start() 调用
Distribute.ReleaseAvailable = OnReleaseAvailable;
AppCenter.Start(...);
IOS:
打开 AppDelegate.cs 并在 FinishedLaunching() 方法中添加 Start() 调用
Distribute.ReleaseAvailable = OnReleaseAvailable;
AppCenter.Start(...);
回复:https ://docs.microsoft.com/en-us/appcenter/sdk/distribute/xamarin#2-start-app-center-distribute
推荐阅读
- android - Android Q 保存的 Uris 在新手机上是否有效?
- angular - Angular 7 - 自定义烤面包机不显示消息
- javascript - 不能让我的方法连接 2 个值
- java - 如何在 Janusgraph 中进化模式?
- php - 在 Wordpress 中添加多个自定义帖子类型
- scala - 使用 Spark / Scala 根据列值减少组中的行
- angular - 如何在 rxjs 中停止可观察的共享
- angular - 对于我的应用程序中的特定页面并且仅在特定的笔记本电脑中,我得到 net::err_aborted 404 角度
- java - Java在int中找到第二个前导数字
- ios - IOS 切换控件在 openGL 支持的 UIView 中滚动