App First Run Detection with Uno Platform and UWP

Xamarin Uno Platform WinUI

3 years ago

Recently, James Montemagno published a blog post about the detection of first app run with Xamarin.Essentials. I thought it would be interesting to write a post about how the same would be accomplished with Uno Platform and UWP.

First Run Setting

The simplest way to detect the first run of your application is via a boolean setting flag. Uno Platform and UWP provide ApplicationData.Current.LocalSettings to allow storing local settings for our application. To make things simple, we wrap the setting access in a class:

The boolean flag defaults to true if no value is found in settings. Now we can easily use it to check if the application is running for the first time:

Version Tracking with Xamarin.Essentials

To get more flexibility for version tracking, there Xamarin.Essentials offers the version tracking API. Luckily, thanks to the magic of Uno Platform, we can use this API not only on mobile and desktop platforms, but on WebAssembly as well! You can install the preview Uno.Xamarin.Essentials NuGet package, and use the Xamarin.Essentials API for version tracking the same way as mentioned in James' blog post without skipping a beat.

Launch Tracking with Uno.UI.Toolkit

If you prefer a more UWP-like API, you are in luck, as I created a pull request to add LaunchTracker helper to the Uno.UI.Toolkit package. Version tracking in the API is based on the Xamarin.Essentials VersionTracking, with UWP-like semantics:

I also added additional properties to track launch dates and launch count. These can be used to display recurring messages or prompts, for example for app rating.

Note that if you have a UWP-only app, you can still use this API by installing the Uno.UI NuGet package, which provides the toolkit functionality for UWP.