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.
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
- Get progress events on an individual package download or on the whole update
- 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.
- Implement the mandatory update logic in your app code (would need to be done before mandatory update itself)
- 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.
Remarks:
- 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.
- 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
Comments
- Anonymous
February 24, 2017
How does this manual update relate to the automatic app updates done by Windows Update? Can I force my app to only download updates through RequestDownloadAndInstallStorePackageUpdatesAsync and prevent updates from WIndows Update?- Anonymous
February 27, 2017
Hey Rafal,I believe there might be some confusion. Windows update is the mechanism by which all Windows related updates (e.g. Windows and UWP apps from the Store) are downloaded. The aforementioned API (RequestDownloadAndInstallStorePackageUpdatesAsync) simply provides UWP apps with a method to invoke the Windows Update machinery to start the update process, rather than being it's own update infrastructure.Does that make sense?ThanksJason Salameh
- Anonymous
- Anonymous
August 28, 2017
The comment has been removed - Anonymous
December 07, 2017
I can update use the GetAppAndOptionalStorePackageUpdatesAsync() and RequestDownloadAndInstallStorePackageUpdatesAsync method. Before install will show a dialog "Update and restart now".I want silent to install app after download complete. I do not want to show "Update and restart now" dialog. Whether have some method to disable this dialog to show?Thanks- Anonymous
December 08, 2017
There is no silent install at this time. If the user has auto-updates turned on for the device the app would silent update for them. The API is to accelerate updates or notify users that might not have automatic updating turned on. Due to this user consent is required.John.- Anonymous
December 12, 2017
Our app is always running at foreground. Although users enable auto updates, our app may be can not update. We want to update our app when it is running without anyone do any input. Maybe we update our app at midnight. How to update app when it is always running?
- Anonymous
- Anonymous