user10200885
user10200885

Reputation:

App Center Distribute – In-app updates for Xamarin Forms

I am reading this documentation about app center in-app updates. I want to try it so that every time there is a release of my app I don't need to uninstall my app and install the new release everytime. There is a sample code in the documentation but I don't know where to put it or how it works the documentation is not clear. The code below is the sample code from the documentation. My problem is how can I implement in-app updates for my app?

https://learn.microsoft.com/en-us/appcenter/sdk/distribute/xamarin

bool OnReleaseAvailable(ReleaseDetails releaseDetails)
{
    // Look at releaseDetails public properties to get version information, release notes text or release notes URL
    string versionName = releaseDetails.ShortVersion;
    string versionCodeOrBuildNumber = releaseDetails.Version;
    string releaseNotes = releaseDetails.ReleaseNotes;
    Uri releaseNotesUrl = releaseDetails.ReleaseNotesUrl;

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

    // On mandatory update, user cannot postpone
    if (releaseDetails.MandatoryUpdate)
    {
        answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install");
    }
    else
    {
        answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install", "Maybe tomorrow...");
    }
    answer.ContinueWith((task) =>
    {
        // If mandatory or if answer was positive
        if (releaseDetails.MandatoryUpdate || (task as Task<bool>).Result)
        {
            // Notify SDK that user selected update
            Distribute.NotifyUpdateAction(UpdateAction.Update);
        }
        else
        {
            // Notify SDK that user selected postpone (for 1 day)
            // Note that this method call is ignored by the SDK if the update is mandatory
            Distribute.NotifyUpdateAction(UpdateAction.Postpone);
        }
    });

    // Return true if you are using your own dialog, false otherwise
    return true;
}

Upvotes: 0

Views: 1737

Answers (1)

SushiHangover
SushiHangover

Reputation: 74134

Android:

You set the callback to your OnReleaseAvailable method via Distribute.ReleaseAvailable

Open MainActivity.cs and add the Start() call inside the OnCreate() method

Distribute.ReleaseAvailable = OnReleaseAvailable;
AppCenter.Start(...);

iOS:

Open your AppDelegate.cs and add the Start() call inside the FinishedLaunching() method

Distribute.ReleaseAvailable = OnReleaseAvailable;
AppCenter.Start(...);

re: https://learn.microsoft.com/en-us/appcenter/sdk/distribute/xamarin#2-start-app-center-distribute

Upvotes: 1

Related Questions