public static async Task <GeolocationAccessStatus> RequestAccessAsync() { var status = GeolocationAccessStatus.Allowed; if (!await PermissionsHelper.CheckFineLocationPermission(CancellationToken.None)) { status = await PermissionsHelper.TryGetFineLocationPermission(CancellationToken.None) ? GeolocationAccessStatus.Allowed : GeolocationAccessStatus.Denied; BroadcastStatus(PositionStatus.Initializing); if (status == GeolocationAccessStatus.Allowed) { BroadcastStatus(PositionStatus.Ready); // If geolocators subscribed to PositionChanged before the location permission was granted, // make sure to initialize these geolocators now so they can start broadcasting. foreach (var subscriber in _positionChangedSubscriptions) { subscriber.Key.TryInitialize(); } } else { BroadcastStatus(PositionStatus.Disabled); foreach (var subscriber in _positionChangedSubscriptions) { subscriber.Key.WaitForPermissionFromBackground(); } } } return(status); }
private async void InitializeIfPermissionIsGranted() { // If the user has granted the location permission while the app was in background, Initialize if (await PermissionsHelper.CheckFineLocationPermission(CancellationToken.None)) { TryInitialize(); CoreApplication.Resuming -= CoreApplication_Resuming; } }
public static async Task <GeolocationAccessStatus> RequestAccessAsync() { if (!await PermissionsHelper.CheckFineLocationPermission(CancellationToken.None)) { return(await PermissionsHelper.TryGetFineLocationPermission(CancellationToken.None) ? GeolocationAccessStatus.Allowed : GeolocationAccessStatus.Denied); } return(GeolocationAccessStatus.Allowed); }
public static async Task <GeolocationAccessStatus> RequestAccessAsync() { var status = GeolocationAccessStatus.Allowed; if (!await PermissionsHelper.CheckFineLocationPermission(CancellationToken.None)) { status = await PermissionsHelper.TryGetFineLocationPermission(CancellationToken.None) ? GeolocationAccessStatus.Allowed : GeolocationAccessStatus.Denied; BroadcastStatus(PositionStatus.Initializing); if (status == GeolocationAccessStatus.Allowed) { BroadcastStatus(PositionStatus.Ready); } else { BroadcastStatus(PositionStatus.Disabled); } } return(status); }