[英]Force users to update to latest version
我在 Play 和 App Store 中發布了一個應用程序,現在我正在為 Play (Android) 和 App Store (iOS) 發布該應用程序的新版本。 現在,我希望所有用戶在使用該應用程序時都更新到新版本,並且不允許他們在不更新到新版本的情況下繼續使用舊版本的應用程序。
任何人都可以建議我如何強制用戶在 Play 和 App 商店發布應用程序后將其更新到最新版本?
我們必須停止Play 和 App Store 中的舊版本。
為了未來不要停止(如果我們有一些主機 - 我們應該擁有它:)):
祝你好運
我不知道這是否是專業的方式。但這是我想到的想法。
在 App.cs 或 Mainpage.cs 和 API 中添加具有該應用程序版本的變量,並將當前版本作為響應。
現在檢查應用程序的版本和當前版本並重定向到主頁/任何其他頁面。
var version = 1.0;
var currentversion = 2.0; /* from API */
if(version == currentversion)
{
Navigation.PushModalAsync(new HomePage());
}
else
{
Navigation.PushModalAsync(new UpdatePage());
}
我的應用程序是如何做的,當應用程序在MyActivity
啟動時,我有下面的代碼
private void CompareVersion()
{
double currentVersion = 0d;
double appStoreversion =Convert.ToDouble(CosntValues.PlayStoreValues);
bool IsUpdateRequired = false;
if (Context.PackageName != null)
{
PackageInfo info = Context.PackageManager.GetPackageInfo(Context.PackageName, PackageInfoFlags.Activities);
string currentVersionStrig = info.VersionName;
currentVersion = Convert.ToDouble(currentVersionStrig);
}
try
{
if (IsUpdateRequired == false)
{
if (CheckNetConnection.IsNetConnected())
{
using (var webClient = new System.Net.WebClient())
{
var task = new VersionChecker();
task.Execute();
if ((appStoreversion.ToString() != currentVersion.ToString() && (appStoreversion > currentVersion)))
{
IsUpdateRequired = true;
}
}
}
}
if (IsUpdateRequired)
{
Activity.RunOnUiThread(() =>
{
AlertDialog dialog = null;
var Alertdialog = new Android.App.AlertDialog.Builder(Context);
Alertdialog.SetTitle("Update Available");
Alertdialog.SetMessage($"A new version of [" + appStoreversion + "] is available. Please update to version [" + appStoreversion + "] now.");
Alertdialog.SetNegativeButton("Cancel", (sender, e) =>
{
if (dialog == null)
{
dialog = Alertdialog.Create();
}
dialog.Dismiss();
});
Alertdialog.SetPositiveButton("Update", async (sender, e) =>
{
string appPackage = string.Empty;
try
{
appPackage = Application.Context.PackageName;
await Utilities.Logout(this.Activity);
var ints = new Intent(Intent.ActionView, Android.Net.Uri.Parse("market://details?id=" + appPackage));
ints.SetFlags(ActivityFlags.ClearTop);
ints.SetFlags(ActivityFlags.NoAnimation);
ints.SetFlags(ActivityFlags.NewTask);
Application.Context.StartActivity(ints);
//StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse("market://details?id=" + "com.sisapp.in.sisapp")));
}
catch (ActivityNotFoundException)
{
var apppack = Application.Context.PackageName;
//Default to the the actual web page in case google play store app is not installed
//StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://play.google.com/store/apps/details?id=" + "com.app.in.app")));
await Utilities.Logout(this.Activity);
var ints = new Intent(Intent.ActionView, Android.Net.Uri.Parse("market://details?id=" + appPackage));
ints.SetFlags(ActivityFlags.ClearTop);
ints.SetFlags(ActivityFlags.NoAnimation);
ints.SetFlags(ActivityFlags.NewTask);
Application.Context.StartActivity(ints);
}
//this kills the app
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
System.Environment.Exit(1);
});
if (dialog == null)
dialog = Alertdialog.Create();
dialog.Show();
});
}
}
catch (Exception ex)
{
var objLog = new LogService();
objLog.MobileLog(ex, SISConst.UserName);
}
}
后面是兩個單獨的上面使用的類
public class VersionChecker : AsyncTask
{
protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
{
var val1 = Jsoup.Connect("https://play.google.com/store/apps/details?id=" + "com.app.in.app" + "&hl=en")
.Timeout(30000).UserAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").Referrer("http://www.google.com")
.Get();
var val2 = val1.Select(".htlgb");
var val3 = val2.Get(7).ToString();
//here mobile app version is of 3 values like 2.1, 4.2 etc
var version = val3.Substring(val3.IndexOf(">") + 1, 3); //fetching only 3 values ex 1.1
CosntValues.PlayStoreValues = version;
return version;
}
}
public static class CosntValues
{
public static string PlayStoreValues { get; set; }
}
免責聲明:使用您的應用程序包名稱和以上代碼靜態支持 1.1、1.2 等 3 位版本。希望對您有所幫助
有了這個插件,我找到了一個很好的解決方案,並且在生產中完美運行。 我強烈推薦這個插件。 有了這個解決方案,你甚至可以讓用戶直接從你的應用程序去商店
例如:
var isLatest = await CrossLatestVersion.Current.IsUsingLatestVersion();
if (!isLatest) //If the user does not have the last version
{
var update = await DisplayAlert("New version available", "There is a new version of our app. Would you like to download it?", "Yes", "No");
if (update)
{
//Open the store
await CrossLatestVersion.Current.OpenAppInStore();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.