Browse Source

Clean up and add location permissions in windows phone project

pull/223/merge
Christian Arenas 7 years ago
parent
commit
d75f48035f
2 changed files with 25 additions and 6 deletions
  1. +24
    -6
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs
  2. +1
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest

+ 24
- 6
src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs View File

@ -3,6 +3,8 @@ using eShopOnContainers.Core.Helpers;
using eShopOnContainers.Services;
using eShopOnContainers.Core.ViewModels.Base;
using System.Threading.Tasks;
using eShopOnContainers.Core.Models.Location;
using eShopOnContainers.Core.Services.Location;
using Plugin.Geolocator;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
@ -52,6 +54,13 @@ namespace eShopOnContainers
{
await GetRealLocation();
}
if (!Settings.UseMocks && !string.IsNullOrEmpty(Settings.UserId))
{
await SendCurrentLocation();
}
base.OnResume();
}
protected override void OnSleep()
@ -59,14 +68,10 @@ namespace eShopOnContainers
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
private async Task GetRealLocation()
{
var locator = CrossGeolocator.Current;
locator.AllowsBackgroundUpdates = true;
locator.DesiredAccuracy = 50;
var position = await locator.GetPositionAsync(20000);
@ -74,5 +79,18 @@ namespace eShopOnContainers
Settings.Latitude = position.Latitude;
Settings.Longitude = position.Longitude;
}
private async Task SendCurrentLocation()
{
var location = new Location
{
Latitude = Settings.Latitude,
Longitude = Settings.Longitude
};
var locationService = ViewModelLocator.Resolve<ILocationService>();
await locationService.UpdateUserLocation(location,
Settings.AuthAccessToken);
}
}
}
}

+ 1
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest View File

@ -25,5 +25,6 @@
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />
<DeviceCapability Name="location" />
</Capabilities>
</Package>

Loading…
Cancel
Save