コード例 #1
0
        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);
        }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: Geolocator.Android.cs プロジェクト: jokm1/uno-2
        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);
        }