A .NET MAUI package for Android and iOS with the main purpose of detecting if the current device is in the EEA, which would make it subject to the GDPR regulation.
Install via NuGet using:
PM> Install-Package GdprInfo
Register the service in your MauiProgram
file.
using GdprInfo;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
// Other services before...
.ConfigureGdprInfo()
// Other service after...
;
return builder.Build();
}
}
Inject the service via dependency injection in the constructor of the depending class.
private readonly IGdprInfoService _gdprInfoService;
public MyConstructor(IGdprInfoService gdprInfoService)
{
_gdprInfoService = gdprInfoService;
}
Check if device is in European Economic Area (EEA):
bool result = _gdprInfoService.IsDeviceInEeaOrUnknow;
You can also get the ISO country code of the current device
string? isoCode = _gdprInfoService.IsoCountryCode;
If the ISO code is not null and is part of the EEA, you can also get additional information about the country like this:
string? countryName = _gdprInfoService.CountryName;
string? countryNumber = _gdprInfoService.CountryNumber;
string? longCountryCode = _gdprInfoService.LongCountryCode;
The service first tries to get the ISO country code via the device telemetry data i.e. network and SIM provider information. If we can't get it from there we look it up from the device's current local setting. Reasons for why we couldn't receive it from telemetry data could be for example that the device is in Flight Mode or that the device has no SIM card inserted at all.
In case that we couldn't receive the ISO code (unknown), we always have to assume that the device owner is in the EEA. So if the ISO code is unknown, IsDeviceInEeaOrUnknow
will return true
.
The project is kind of archived. I do occasional updates as I require them for personal use, but to be honest, in the mean time there are much better ways of doing what this package was trying to do.