Package.CheckUpdateAvailabilityAsync Package.CheckUpdateAvailabilityAsync Package.CheckUpdateAvailabilityAsync Package.CheckUpdateAvailabilityAsync Package.CheckUpdateAvailabilityAsync Method

Definition

The CheckUpdateAvailabilityAsync method allows developers to check for updates to the main app package listed in the .appinstaller file. It allows the developer to determine if the updates are required due to .appinstaller policy. This method currently only works for applications installed via .appinstaller files.

public : IAsyncOperation<PackageUpdateAvailabilityResult> CheckUpdateAvailabilityAsync()
IAsyncOperation<PackageUpdateAvailabilityResult> CheckUpdateAvailabilityAsync() const;
public IAsyncOperation<PackageUpdateAvailabilityResult> CheckUpdateAvailabilityAsync()
Public Function CheckUpdateAvailabilityAsync() As IAsyncOperation(Of PackageUpdateAvailabilityResult)
Windows.ApplicationModel.Package.checkUpdateAvailabilityAsync().done( /* Your success and error handlers */ );

Returns

Additional features and requirements

Device family
Windows 10, version 1809 (introduced v10.0.17763.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v7)

Examples

An app developer wants to have a button in their app that allows a user to check for app updates. To enable the app to check if an update is available, they use the CheckUpdateAvailabilityAsync method as shown below.


private async void CheckForUpdatesButton_Click(object sender, RoutedEventArgs e)
{
    PackageUpdateAvailabilityResult result = await Package.Current.CheckUpdateAvailabilityAsync();
    switch (result.Availability)
    {
        case PackageUpdateAvailability.Available:
            GoToUpdateAvailableUIView();
            break;
        case PackageUpdateAvailability.Required:
            GoToUpdateRequiredUIView();
            break;
        case PackageUpdateAvailability.NoUpdates:
            ShowNoUpdateAvailableDialog(); // dismissable ‘Ok’ dialog
            break;
        case PackageUpdateAvailability.Unknown:
        default:
            // Log and ignore error.
            Logger.Log($"No update information associated with app {Package.Current.DisplayName}");
            ShowNoUpdateAvailableDialog(); // dismissable ‘Ok’ dialog
            break;
    }
}

From inside the app, the developer wants to check for updates and start the update process if updates are available.


public async void CheckForAvailableUpdatesAndLaunchAsync(string targetPackageFullName)
{
    PackageManager pm = new PackageManager();
    Package package = pm.FindPackageForUser(string.Empty /*current user*/, targetPackageFullName);

    PackageUpdateAvailabilityResult result = await package.CheckUpdateAvailabilityAsync();
    switch (result.Availability)
    {
        case PackageUpdateAvailability.Available:
            GoToUpdateAvailableUIView();
            break;
        case PackageUpdateAvailability.Required:
            GoToUpdateRequiredUIView();
            break;
        case PackageUpdateAvailability.NoUpdates:
            // Launch target app and close AppInstaller
            LaunchTargetApp(targetPackageFullName);
            await ConsolidateAppInstallerView();
            break;
        case PackageUpdateAvailability.Unknown:
        default:
            // Log and ignore error.
            Logger.Log($"No update information associated with app {targetPackageFullName}");
            // Launch target app and close AppInstaller
            LaunchTargetApp(targetPackageFullName);
            await ConsolidateAppInstallerView();
            break;
    }
}

See also