Files
EmptyMauiApp/MauiApp/Core/System/Device/DeviceService.cs
2023-10-18 19:02:51 +02:00

32 lines
847 B
C#

using MauiApp.Core.System.Device.Contracts;
using MauiApp.Core.System.LocalStorage.Contracts;
namespace MauiApp.Core.System.Device;
public class DeviceService : IDeviceService
{
private readonly ILocalStorage _localStorageService;
public DeviceService(ILocalStorage localStorageService)
{
this._localStorageService = localStorageService;
}
public async Task<string> GetDeviceId()
{
string deviceId = await _localStorageService.GetItemString("deviceId");
Guid randomUuid;
if (string.IsNullOrEmpty(deviceId))
{
randomUuid = Guid.NewGuid();
await _localStorageService.SetItemString("deviceId", randomUuid.ToString());
}
else
{
randomUuid = Guid.Parse(deviceId);
}
return randomUuid.ToString();
}
}