コード例 #1
0
 /// <summary>
 /// Simulate getting new version information from internet
 /// </summary>
 /// <param name="forceUpdate"></param>
 /// <returns></returns>
 private Plugin.XF.AppInstallHelper.AppVersion CheckVersion(bool forceUpdate)
 {
     Plugin.XF.AppInstallHelper.AppVersion version2 = new Plugin.XF.AppInstallHelper.AppVersion
     {
         ForceUpdate  = forceUpdate,
         ReleaseNotes = "1. testing update\r\n2. Please install",
         VersionCode  = 4,
         VersionName  = "2.1.0",
         AndroidPath  = "https://github.com/JimmyPun610/Plugin.XF.AppInstallHelper/raw/master/App/plugin.xf.appinstallhelper.sample_v4.apk",
         iOSPath      = ""
     };
     return(version2);
 }
コード例 #2
0
        private async Task <bool> PromptUpdate(Plugin.XF.AppInstallHelper.AppVersion newVerInfo)
        {
            bool confirmUpdate = true;

            if (newVerInfo.ForceUpdate)
            {
                await DisplayAlert($"New version {newVerInfo.VersionName} occur", $"Release notes : \r\n{newVerInfo.ReleaseNotes}", "Update");
            }
            else
            {
                confirmUpdate = await DisplayAlert($"New version {newVerInfo.VersionName} occur", $"Release notes : \r\n{newVerInfo.ReleaseNotes}", "Update", "Skip");
            }
            return(confirmUpdate);
        }
コード例 #3
0
        private async Task installUpdate(Plugin.XF.AppInstallHelper.AppVersion updatedVersion)
        {
            if (updatedVersion.VersionCode > int.Parse(Xamarin.Essentials.VersionTracking.CurrentBuild))
            {
                bool confirmUpdate = await PromptUpdate(updatedVersion);

                if (confirmUpdate)
                {
                    string installPath = string.Empty;
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        installPath = updatedVersion.iOSPath;
                    }
                    else
                    {
                        installPath = System.IO.Path.Combine(Plugin.XF.AppInstallHelper.InstallationHelper.GetPublicDownloadPath(), "APK.APK");



                        using (HttpClient hc = new HttpClient())
                        {
                            var response = await hc.GetAsync(updatedVersion.AndroidPath);

                            var byteArray = await response.Content.ReadAsByteArrayAsync();

                            System.IO.File.WriteAllBytes(installPath, byteArray);
                        }
                    }
                    bool result = await Plugin.XF.AppInstallHelper.InstallationHelper.InstallApp(installPath, InstallMode.OutOfAppStore);
                }
            }
            else
            {
                await DisplayAlert("Alert", "There is no more update", "OK");
            }
        }