Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP + .appinstaller: How to detect new version and prompt user and start the upgrade of the app?

Tags:

c#

uwp

I created an app using SDK 17134 .appinstaller, certificate, uploaded to server version 1.0.0.0;

User installs the App. (1.0.0.0)
User opens the App (1.0.0.0)
Then I publish a new version (1.0.0.2).

While the App is open, how can I check on the app that a new version is avaliable on the server, prompt the user and start app update to version 1.0.0.2?

  • I am aware that my app updates silently after it detects a new version (but this only happen on the second time user opens the app.)
like image 1000
Tony Avatar asked Jun 05 '18 23:06

Tony


People also ask

How do I update my UWP app?

Update Windows 10 UWP Apps To change the UWP updates settings, open the Microsoft Store, select the See more “three dots” button next to your profile icon at the top, and click Settings. Under the Settings, in the “App updates” section, turn the toggle button on or off next to “Update apps automatically.”

How do I find my UWP version?

1] Find UWP app version via Settings You can first navigate to the Settings icon at the bottom of the window and then click on About. You may also want to navigate to the related links section and then find “About” section to know the version like in case of Windows Defender Security Center app.

How do I find application installer settings in Windows?

Check App Installer Settings in Windows To do this, head to Settings > Apps > Apps & features. At the top, you'll see a Choose where to get apps section. If the dropdown is set to The Microsoft Store only (recommended) then you won't be able to install apps from anywhere else.

What is Onlaunch?

This element signifies that the deployment service will check for an update to the App Installer file when the app launches.


2 Answers

Windows 1809 introduced a couple of tools to help in this regard. You can use the Package.GetAppInstallerInfo() method to get the URI from the .AppInstaller.

AppInstallerInfo info = Windows.ApplicationModel.Package.Current.GetAppInstallerInfo();

You can also use Package.CheckUpdateAvailabilityAsync() to see if an update is available from the server indicated in the .AppInstaller.

PackageUpdateAvailabilityResult result = await currentPackage.CheckUpdateAvailabilityAsync();
switch (result.Availability)
{
    case PackageUpdateAvailability.Available:
        GoToUpdateAvailableUIView();
        break;
    case PackageUpdateAvailability.Required:
        GoToUpdateRequiredUIView();
        break;
    case PackageUpdateAvailability.NoUpdates:
        ShowNoUpdateAvailableDialog(); 
        break;
    case PackageUpdateAvailability.Unknown:
    default:
        // Log and ignore or whatever
        break;
}
like image 72
NSouth Avatar answered Nov 03 '22 01:11

NSouth


As the .appinstaller file is just an XML file, you can request its contents from your server and then check for the version inside. You can then compare it with Package.Current.Id.Version and in case it is newer, you may notify the user to close the app to update it. This however presumes the system has already checked ahead that the update is available, which depends on what you have selected in the dialog while creating the package:

Package creation dialog

If you are checking for updates everytime the application runs, just display the prompt after a slight delay to make sure the system has had time to find out about the new version. If you have set an interval, it is more tricky, so you could ideally notify the user after two-times longer interval than you have set, so that you can be sure that the system check has gone through before that.

like image 39
Martin Zikmund Avatar answered Nov 03 '22 01:11

Martin Zikmund