xamarinxamarin.iosvisual-studio-app-centervisual-studio-app-center-distribute

Appcenter distribute in-app updates not working in Xamarin.iOS


I am trying to distribute an internal iOS app (built using Xamarin.iOS) using Visual Studio AppCenter, but can't seem to get in-app updates to work.

when I download and install the app (through the email link) the browser never opens to register for in-app updates, and when I distribute a new release to that group, the app does not offer an update.

I've followed the instructions here.

I've added the info.plist entries and started the appcenter distribute module. Analytics + Crash reporting are working OK so the AppCenter ID is fine.

Any help would be appreciated.


Solution

  • If you want to create your own VersionChecker, in the override of the ViewDidLoad of the first view controller, you can call the CheckVersion() function

    public override void ViewDidLoad()
    {        
        base.ViewDidLoad();
        CheckVersion();
        OtherCode();
    }
    

    And then in the CheckVersion function you could do something like this

            public async void CheckVersion()
            {
                var newVersionAsString = new VersionObject();
                string responseContent = string.Empty;
    
                using (HttpClient httpClient = new HttpClient())
                {
                    try
                    {
                        var versionCheckUri = "https://gist.githubusercontent.com/saamerm/af01aec0187d38a22fdd9b4378afc9c3/raw/680332a9a45eb015bc17fbf817fbac537348e3d4/Version.json"
                        using (HttpResponseMessage httpResponse = await httpClient.GetAsync(versionCheckUri))
                        {
                            if (httpResponse.StatusCode == System.Net.HttpStatusCode.OK)
                            {
                                responseContent = await httpResponse.Content.ReadAsStringAsync();
                                newVersionAsString = JsonConvert.DeserializeObject<VersionObject>(responseContent);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
    
                var currentVersion = new Version(NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"].ToString());
    
                if (currentVersion != null && !string.IsNullOrWhiteSpace(newVersionAsString) && (new Version(newVersionAsString.latestVersion)) > currentVersion)
                {
                    string AppleStoreAppUrl = "itms-apps://itunes.apple.com/us/app/pages/{YOURAPPURL}?mt=8";
                    var alert = new AlertView { ViewController = this, Title = "Update Required", Message = "To continue using this mobile app, please install the latest version." };
                    alert.AddAction("Update Now", ActionStyle.Cancel, (action) => { UIApplication.SharedApplication.OpenUrl(new NSUrl(AppleStoreAppUrl)); this.Dispose(); }).Show();
                }
    

    where VersionObject we got from jsonutils.com

     public class VersionObject
        {
            public string latestVersion { get; set; }
        }
    

    Please test this before using it, I can see an instance where it may not work