Skip to content

Commit d75f480

Browse files
committed
Clean up and add location permissions in windows phone project
1 parent 1d3cad9 commit d75f480

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using eShopOnContainers.Services;
44
using eShopOnContainers.Core.ViewModels.Base;
55
using System.Threading.Tasks;
6+
using eShopOnContainers.Core.Models.Location;
7+
using eShopOnContainers.Core.Services.Location;
68
using Plugin.Geolocator;
79
using Xamarin.Forms;
810
using Xamarin.Forms.Xaml;
@@ -52,27 +54,43 @@ protected override async void OnStart()
5254
{
5355
await GetRealLocation();
5456
}
57+
58+
if (!Settings.UseMocks && !string.IsNullOrEmpty(Settings.UserId))
59+
{
60+
await SendCurrentLocation();
61+
}
62+
63+
base.OnResume();
5564
}
5665

5766
protected override void OnSleep()
5867
{
5968
// Handle when your app sleeps
6069
}
6170

62-
protected override void OnResume()
63-
{
64-
// Handle when your app resumes
65-
}
66-
6771
private async Task GetRealLocation()
6872
{
6973
var locator = CrossGeolocator.Current;
74+
locator.AllowsBackgroundUpdates = true;
7075
locator.DesiredAccuracy = 50;
7176

7277
var position = await locator.GetPositionAsync(20000);
7378

7479
Settings.Latitude = position.Latitude;
7580
Settings.Longitude = position.Longitude;
7681
}
82+
83+
private async Task SendCurrentLocation()
84+
{
85+
var location = new Location
86+
{
87+
Latitude = Settings.Latitude,
88+
Longitude = Settings.Longitude
89+
};
90+
91+
var locationService = ViewModelLocator.Resolve<ILocationService>();
92+
await locationService.UpdateUserLocation(location,
93+
Settings.AuthAccessToken);
94+
}
7795
}
78-
}
96+
}

src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
<Capabilities>
2626
<Capability Name="internetClient" />
2727
<Capability Name="privateNetworkClientServer" />
28+
<DeviceCapability Name="location" />
2829
</Capabilities>
2930
</Package>

0 commit comments

Comments
 (0)