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)
{
    // Get the current app's package for the current user.
    PackageManager pm = new PackageManager();
    Package currentPackage = pm.FindPackageForUser(string.Empty, Package.Current.Id.FullName);

    PackageUpdateAvailabilityResult result = await currentPackage.CheckUpdateAvailabilityAsync();
    switch (result.Availability)
    {
        case PackageUpdateAvailability.Available:
            GoToUpdateAvailableUIView();
            break;
        case PackageUpdateAvailability.Required:
            GoToUpdateRequiredUIView();
            break;
        case PackageUpdateAvailability.NoUpdates:
            // Dismissable ‘Ok’ dialog.
            ShowNoUpdateAvailableDialog(); 
            break;
        case PackageUpdateAvailability.Unknown:
        default:
            // Log and ignore error.
            Logger.Log($"No update information associated with app {Package.Current.DisplayName}");
            // Dismissable ‘Ok’ dialog.
            ShowNoUpdateAvailableDialog();
            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)
{
    // Get the current app's package for the current user.
    PackageManager pm = new PackageManager();
    Package package = pm.FindPackageForUser(string.Empty, 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;
    }
}

Remarks

If you try to use this method on the Package object returned by the Current property, this method will fail with an "Access denied" error. This is a known issue that may be fixed in a future release. The example on this page demonstrates how to retrieve update information about the current app's package.

This method is not supported in JavaScript. However, you can create a Windows Runtime component that calls this method and then call this component from a JavaScript UWP app. For more information, see App Installer file API issues.

See also