Example #1
0
        public static async Task <AccessState> RequestAccess(this CLLocationManager locationManager, bool background)
        {
            var status = locationManager.GetCurrentStatus(background);

            if (status == AccessState.Available)
            {
                return(status);
            }

            var task = locationManager
                       .WhenAccessStatusChanged(background)
                       .StartWith()
                       .Take(1)
                       .ToTask();

#if __IOS__
            if (background)
            {
                locationManager.RequestAlwaysAuthorization();
            }
            else
            {
                locationManager.RequestWhenInUseAuthorization();
            }
#elif !__TVOS__
            locationManager.RequestAlwaysAuthorization();
#endif

            status = await task;
            return(status);
        }
Example #2
0
        public static async Task <AccessState> RequestAccess(this CLLocationManager locationManager, bool background)
        {
            var status = locationManager.GetCurrentStatus(background);

            if (status != AccessState.Unknown)
            {
                return(status);
            }

            var task = locationManager
                       .WhenAccessStatusChanged(background)
                       .Take(1)
                       .ToTask();

            if (background)
            {
                locationManager.RequestAlwaysAuthorization();
            }
            else
            {
                locationManager.RequestWhenInUseAuthorization();
            }

            status = await task;
            return(status);
        }
Example #3
0
        public static async Task <AccessState> RequestAccess(this CLLocationManager locationManager, bool background)
        {
            var status = locationManager.GetCurrentStatus(background);

            if (status != AccessState.Unknown)
            {
                return(status);
            }

            var task = locationManager
                       .WhenAccessStatusChanged(background)
                       .StartWith()
                       .Take(1)
                       .ToTask();

//#if __IOS__
            if (background)
            {
                locationManager.RequestAlwaysAuthorization();
            }
            else
            {
                locationManager.RequestWhenInUseAuthorization();
            }
//#elif !__TVOS__
//            locationManager.RequestAlwaysAuthorization();
//#endif
            status = await task.ConfigureAwait(false);

            return(status);
        }
Example #4
0
        public static AccessState GetCurrentStatus <T>(this CLLocationManager locationManager, bool background) where T : CLRegion
        {
            if (!CLLocationManager.IsMonitoringAvailable(typeof(T)))
            {
                return(AccessState.NotSupported);
            }

            return(locationManager.GetCurrentStatus(background));
        }
Example #5
0
        public static async Task <AccessState> RequestAccess(this CLLocationManager locationManager, bool background)
        {
            var status = locationManager.GetCurrentStatus(background);

            if (status != AccessState.Unknown)
            {
                return(status);
            }

            status = await locationManager
                     .WhenAccessStatusChanged(background)
                     .Take(1)
                     .ToTask();

            return(status);
        }