Clean up and add location permissions in windows phone project
This commit is contained in:
		
							parent
							
								
									1d3cad9e67
								
							
						
					
					
						commit
						d75f48035f
					
				| @ -3,6 +3,8 @@ using eShopOnContainers.Core.Helpers; | |||||||
| using eShopOnContainers.Services; | using eShopOnContainers.Services; | ||||||
| using eShopOnContainers.Core.ViewModels.Base; | using eShopOnContainers.Core.ViewModels.Base; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
|  | using eShopOnContainers.Core.Models.Location; | ||||||
|  | using eShopOnContainers.Core.Services.Location; | ||||||
| using Plugin.Geolocator; | using Plugin.Geolocator; | ||||||
| using Xamarin.Forms; | using Xamarin.Forms; | ||||||
| using Xamarin.Forms.Xaml; | using Xamarin.Forms.Xaml; | ||||||
| @ -52,6 +54,13 @@ namespace eShopOnContainers | |||||||
|             { |             { | ||||||
|                 await GetRealLocation(); |                 await GetRealLocation(); | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             if (!Settings.UseMocks && !string.IsNullOrEmpty(Settings.UserId)) | ||||||
|  |             { | ||||||
|  |                 await SendCurrentLocation(); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             base.OnResume(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         protected override void OnSleep() |         protected override void OnSleep() | ||||||
| @ -59,14 +68,10 @@ namespace eShopOnContainers | |||||||
|             // Handle when your app sleeps |             // Handle when your app sleeps | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         protected override void OnResume() |  | ||||||
|         { |  | ||||||
|             // Handle when your app resumes |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         private async Task GetRealLocation() |         private async Task GetRealLocation() | ||||||
|         { |         { | ||||||
|             var locator = CrossGeolocator.Current; |             var locator = CrossGeolocator.Current; | ||||||
|  |             locator.AllowsBackgroundUpdates = true; | ||||||
|             locator.DesiredAccuracy = 50; |             locator.DesiredAccuracy = 50; | ||||||
| 
 | 
 | ||||||
|             var position = await locator.GetPositionAsync(20000); |             var position = await locator.GetPositionAsync(20000); | ||||||
| @ -74,5 +79,18 @@ namespace eShopOnContainers | |||||||
|             Settings.Latitude = position.Latitude; |             Settings.Latitude = position.Latitude; | ||||||
|             Settings.Longitude = position.Longitude; |             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); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -25,5 +25,6 @@ | |||||||
|   <Capabilities> |   <Capabilities> | ||||||
|     <Capability Name="internetClient" /> |     <Capability Name="internetClient" /> | ||||||
|     <Capability Name="privateNetworkClientServer" /> |     <Capability Name="privateNetworkClientServer" /> | ||||||
|  |     <DeviceCapability Name="location" /> | ||||||
|   </Capabilities> |   </Capabilities> | ||||||
| </Package> | </Package> | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user