Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 0f0a7fb

Browse files
committed
App now gracefully handles the location service being turned off in the Windows OS.
1 parent 2e87eac commit 0f0a7fb

File tree

1 file changed

+13
-4
lines changed
  • src/Mobile/eShopOnContainers/eShopOnContainers.Core

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using eShopOnContainers.Core.Models.Location;
2+
using eShopOnContainers.Core.Services.Dependency;
23
using eShopOnContainers.Core.Services.Location;
34
using eShopOnContainers.Core.Services.Settings;
45
using eShopOnContainers.Core.ViewModels.Base;
56
using eShopOnContainers.Services;
7+
using System;
8+
using System.Diagnostics;
69
using System.Globalization;
710
using System.Threading.Tasks;
811
using Xamarin.Forms;
912
using Xamarin.Forms.Xaml;
10-
using eShopOnContainers.Core.Services.Dependency;
1113

1214
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
1315
namespace eShopOnContainers
@@ -76,10 +78,17 @@ private async Task GetGpsLocation()
7678

7779
// Delay getting the position to ensure that the UI has finished updating
7880
await Task.Delay(2000);
79-
var position = await locator.GetPositionAsync();
81+
try
82+
{
83+
var position = await locator.GetPositionAsync();
8084

81-
_settingsService.Latitude = position.Latitude.ToString();
82-
_settingsService.Longitude = position.Longitude.ToString();
85+
_settingsService.Latitude = position.Latitude.ToString();
86+
_settingsService.Longitude = position.Longitude.ToString();
87+
}
88+
catch (Exception ex)
89+
{
90+
Debug.WriteLine(ex);
91+
}
8392
}
8493
else
8594
{

0 commit comments

Comments
 (0)