Share via


Developer controlled app updates

Keeping apps up to date is a somewhat tedious task; it requires extra work on developers to check versions, guide the user to the store and hope they install the update - the result is lots of user confusion causing old apps to continue existing in the wild. We've heard this feedback from developers and are super excited to announce that starting at build 14393 and beyond, Windows 10 allows developers to make stronger guarantees around app updates!

Doing this requires a few simple APIs, creates a consistent and predictable user experience and lets developers to focus on what they do best while allowing Windows to do the heavy lifting. Here's what the UI would look like to a user.

 

Non Blocking Update

 

More details? Sure thing!

Implementing in app

There are two fundamental ways that app updates can be managed. In both cases, the net result for these methods is the same - the update is applied. However, in one case, you can choose to let the system do all the work while in the other case you might want to have a deeper level of control over the user experience.

Simple updates

First and foremost is the very simple API call that tells the system to check for updates, download them and then request permission from the user to install them. You'll start by using the StoreContext class to get StorePackageUpdate objects, download and install them.

 using Windows.Services.Store;

private async void GetEasyUpdates()
{
    StoreContext updateManager = StoreContext.GetDefault();
    IReadOnlyList<StorePackageUpdate> updates = await updateManager.GetAppAndOptionalStorePackageUpdatesAsync();

    if (updates.Count > 0)
    {
        IAsyncOperationWithProgress<StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = 
            updateManager.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);
        StorePackageUpdateResult result = await downloadOperation.AsTask();
    }
}

At this point the user has two options they can choose from; apply now or defer the update. Whatever choice the user makes will be returned back to via the StorePackageUpdateResult object allowing developers to take further actions such as closing down the app if the update is required to continue or simply trying again later.

Finer controlled updates

For developers who are looking to have a completely customized experience, we have a solution for you as well! Additional APIs are provided which enable more control over the update process; this control is a dial that you as a developer can control. The platform enables you to do the following

  1. Get progress events on an individual package download or on the whole update
  2. Apply updates at the user's and app's convenience rather than one or the other

Developers are able to download updates in the background (while app is in use) then request the user install updates, if they decline, you can simply disable capabilities affected by the update if you choose.

Download Updates

 private async void DownloadUpdatesAsync()
{
    StoreContext updateManager = StoreContext.GetDefault();
    IReadOnlyList<StorePackageUpdate> updates = await updateManager.GetAppAndOptionalStorePackageUpdatesAsync();

    if (updates.Count > 0)
    {
        IAsyncOperationWithProgress<StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation =
            updateManager.RequestDownloadStorePackageUpdatesAsync(updates);

        downloadOperation.Progress = async (asyncInfo, progress) =>
        {
            // Show progress UI
        };

        StorePackageUpdateResult result = await downloadOperation.AsTask();
        if (result.OverallState == StorePackageUpdateState.Completed)
        {
            // Update was downloaded, add logic to request install
        }
    }
}

Install Updates

 private async void InstallUpdatesAsync()
{
    StoreContext updateManager = StoreContext.GetDefault();
    IReadOnlyList<StorePackageUpdate> updates = await updateManager.GetAppAndOptionalStorePackageUpdatesAsync();    

    // Save app state here

    IAsyncOperationWithProgress<StorePackageUpdateResult, StorePackageUpdateStatus> installOperation =
        updateManager.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);

    StorePackageUpdateResult result = await installOperation.AsTask();

    // Under normal circumstances, app will terminate here

    // Handle error cases here using StorePackageUpdateResult from above
}

Making updates mandatory

In some cases, it might actually be desirable to have an update that must be installed to a user's device - making it truly mandatory (e.g. a critical fix to an app that can't wait). In these cases, there are additional measure that you can take to make the update mandatory.

  1. Implement the mandatory update logic in your app code (would need to be done before mandatory update itself)
  2. During submission to the Dev Center, ensure the "Make this update mandatory" box is selected

Implementing app code

In order to take full advantage of mandatory updates, you'll need to make some slight modifications to the code above. You'll need to use the StorePackageUpdate object to determine if the update is mandatory.

 private async bool CheckForMandatoryUpdates()
{
    StoreContext updateManager = StoreContext.GetDefault();
    IReadOnlyList<StorePackageUpdate> updates = await updateManager.GetAppAndOptionalStorePackageUpdatesAsync();

    if (updates.Count > 0)
    {
        foreach (StorePackageUpdate u in updates)
        {
            if (u.Mandatory)
                return true;
        }
    }
    return false;
}

Then you'll need to create a custom in app dialog to inform the user that there is a mandatory update and that they must install it to continue full use of the app. If the user declines the update, the app could either degrade functionality (e.g. prevent online access) or terminate completely (e.g. online only games)

Dev Center

To ensure the StorePackageUpdate shows true for a mandatory update, you will need to mark the update as mandatory in the Dev Center in the Packages page.

mandatory-dev-center

Remarks:

  1. In rare occurences where a device comes back online after a mandatory update has been supersceded with another non-mandatory update, the non-mandatory update will still show up on the device as mandatory given the missed update before it was mandatory.
  2. Developer controlled updates / mandatory updates is currently limited to the Windows Store.

 

While we don't always like to force updates onto our users or devices, it's somestimes a necessary part of the development lifecycle that we can't avoid. Windows 10 makes this process simple, intuitive and managable for both developers and users!

 

Any questions? leave them in the comments!

 

Thanks!

Jason Salameh, Senior Program Manager – Windows Developer Platform