user11287929
user11287929

Reputation:

Properly implement In-App Updates in App Center?

I am reading this documentation/article from Microsoft on how to Distribute Mobile apps with app center. The problem is I really don't understand how to implement this. I have a app on app center (Android) I want to implement mandatory update so that I can eliminate the bugs of the previous version. I tried to distribute the app with mandatory update enabled and it is not working. How can I fix this?

https://learn.microsoft.com/en-us/appcenter/distribution/

Here is what I did I added this code on my App.xaml.cs (XAMARIN FORMS PROJECT):

protected override void OnStart ()
    {
        AppCenter.Start("android={Secret Code};", typeof(Analytics), typeof(Crashes), typeof(Distribute));
        Analytics.SetEnabledAsync(true);
        Distribute.SetEnabledAsync(true);

        Distribute.ReleaseAvailable = OnReleaseAvailable;
    }

    bool OnReleaseAvailable(ReleaseDetails releaseDetails)
    {
        string versionName = releaseDetails.ShortVersion;
        string versionCodeOrBuildNumber = releaseDetails.Version;
        string releaseNotes = releaseDetails.ReleaseNotes;
        Uri releaseNotesUrl = releaseDetails.ReleaseNotesUrl;

        var title = "Version " + versionName + " available!";
        Task answer;

        if (releaseDetails.MandatoryUpdate)
        {
            answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install");
        }
        else
        {
            answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install", "Ask Later");
        }
        answer.ContinueWith((task) =>
        {
            if (releaseDetails.MandatoryUpdate || (task as Task<bool>).Result)
            {
                Distribute.NotifyUpdateAction(UpdateAction.Update);
            }
            else
            {
                Distribute.NotifyUpdateAction(UpdateAction.Postpone);
            }
        });

        return true;
    }

And here is what I added on my MainActivity.cs(ANDROID PROJECT):

AppCenter.Start("{Secret Code}", typeof(Analytics), typeof(Crashes), typeof(Distribute));

Upvotes: 0

Views: 3960

Answers (2)

Saamer
Saamer

Reputation: 5099

There could be a lot of different reasons as to why they are not working. As you can see in the Notes here and here,

  1. Did your testers download the app from the default browser?

  2. Are cookies enabled for the browser in their settings?

Another important point you'll read in the links, is that the feature is only available for listed distribution group users. It is not for all your members. You could use a simple version checker for your purpose instead or you could use a plugin.

Upvotes: 2

hagould
hagould

Reputation: 31

Looking at this App Center documentation here for Xamarin Forms -

You can customize the default update dialog's appearance by implementing the ReleaseAvailable callback. You need to register the callback before calling AppCenter.Start

It looks like you need to swap your current ordering to get in-app updates working.

Upvotes: 3

Related Questions