32 lines
847 B
C#
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();
|
|
}
|
|
} |