Why unique device and installations identifiers are important?
First, let’s define what we mean by a unique device and installation identifiers. Essentially, these are codes that are assigned to individual devices and installations of an app. They allow developers to track usage on a specific device and identify individual installations of the app. This is important because it allows us to understand how users are interacting with our app and identify patterns in usage. For example, if we notice that a particular device is experiencing a high number of crashes, we can use the device ids to track down the specific device and troubleshoot the issue.
Another important use case for unique device and installation identifiers is providing targeted and personalized content or experiences for users. For example, we can use this information to show users personalized advertisements or to offer them special deals or promotions based on their usage patterns.
In addition to these benefits, device and install ids also play an important role in security and fraud prevention. By tracking the usage of our app on specific devices, we can identify and prevent unauthorized access to the app or service. This can help to protect user data and prevent fraud and other malicious activities.
How to get unique identifiers in .NET MAUI?
On Android, you can get a unique device id from the os with accessing Secure.AndroidId.
On iOS, UIDevice.CurrentDevice.IdentifierForVendor is the solution. It requires platform specific knowledge to access the provider APIs. I’ve extended my banditoth.MAUI.Packages library, so you do not need to worry about having this knowledge, just use the banditoth.MAUI.DeviceId NuGet package.
Once you have installed banditoth.MAUI.DeviceId, you need to initalize the plugin within your
CreateMauiApp method. Use the
.ConfigureDeviceIdProvider extension method with the
public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
Use the code with by resolving an instance of
GetDeviceId method returns an unique device identifier. On Android it serves the data from
AndroidId, on iOS and MacCatalyst it uses the
IdentifierForVendor. Windows returns the
GetSystemIdForPublisher().Idas a string.
GetInstallationId method generates an unique identifier for the application, which will be stored until the application is being reinstalled, or the application’s data being erased.