Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 强制用户更新到最新版本_C#_Xamarin.forms_Xamarin.ios_Xamarin.android_App Update - Fatal编程技术网

C# 强制用户更新到最新版本

C# 强制用户更新到最新版本,c#,xamarin.forms,xamarin.ios,xamarin.android,app-update,C#,Xamarin.forms,Xamarin.ios,Xamarin.android,App Update,我在Play和app store中发布了一个应用程序,现在我正在为Play(Android)和app store(iOS)发布一个新版本。现在,我希望所有用户在使用应用程序时更新到新版本,并且不允许他们在不更新到新版本的情况下继续使用旧版本的应用程序 有谁能建议我如何在Play和app store中发布应用程序后强制用户将其更新为最新版本?我们必须停止Play和app store中的旧版本 未来不要停止(如果我们有主机,我们应该有:): 以某种方式将版本保存到服务器端 每次需要时,检查当前版本

我在Play和app store中发布了一个应用程序,现在我正在为Play(Android)和app store(iOS)发布一个新版本。现在,我希望所有用户在使用应用程序时更新到新版本,并且不允许他们在不更新到新版本的情况下继续使用旧版本的应用程序


有谁能建议我如何在Play和app store中发布应用程序后强制用户将其更新为最新版本?

我们必须停止Play和app store中的旧版本

未来不要停止(如果我们有主机,我们应该有:):

  • 以某种方式将版本保存到服务器端
  • 每次需要时,检查当前版本:getPackageManager().getPackageInfo(getPackageName(),0).versionCode和服务器版本,并根据需要强制更新

祝你好运

我不知道这是否是专业的方式,但这正是我想到的想法

在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; }
}
免责声明:使用您的应用程序包名称&以上代码静态支持3位版本,如1.1、1.2等。 希望它能帮助你

使用插件,我找到了一个很好的解决方案,并在生产中完美运行。我强烈推荐这个插件。使用此解决方案,您甚至可以让用户直接从应用程序进入商店

例如:

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();
            }
        }

要使其工作,此代码必须包含在Play和app store右侧的现有应用程序中。?我在发布应用程序时没有包括这些内容。我正在寻找任何方法,我们可以强制执行这一点,同时发布应用程序更新@senthamizhSorry兄弟,不知道。Google Play将通知playstore中是否有更新,但据我所知,强制用户在没有上述方法的情况下进行更新是不可能的。要使其正常工作,此代码必须包含在Play和app store中的现有应用中。?我在发布应用程序时没有包括这些内容。我正在寻找任何方法,我们可以强制执行这一点,同时发布应用程序更新@Hovanes MosoyanYes,你说得对。在这种情况下,我们必须在Play和/或App store中停止旧版本。我们想要使用的功能可能在应用商店中,也可能在Google Play中,但我在那里找不到这样的功能)这段代码需要包含在商店中已经发布的应用中才能工作。但在我发布应用程序时,我没有做过这样的事情。因此,我正在寻找在play and app store中发布更新时的一个选项,如果有类似的选项。不,只需在当前应用中添加此代码,而不考虑是否发布应用。但这不会影响已在play store中使用应用的用户。它将适用于我的应用程序的下一个应用程序版本。但不是这个版本的。。。!明显地当你发布新版本时,已经在使用你的应用程序的用户不会弹出窗口。从第二次开始他们应该得到的谢谢。。在应用商店和游戏商店中发布应用程序更新时,似乎没有办法做到这一点。在我启动应用程序时,放置这段代码的最佳位置是什么?您应该将其放在应用程序的开头,以便要求用户进行更新。我在我的登录页面上有一些验证代码,之后我检查了版本。