示例#1
0
        /// <summary>
        /// Stop listening
        /// </summary>
        public Task <bool> StopListeningAsync()
        {
            if (!isListening)
            {
                return(Task.FromResult(true));
            }

            isListening = false;
#if __IOS__
            if (CLLocationManager.HeadingAvailable)
            {
                manager.StopUpdatingHeading();
            }

            // it looks like deferred location updates can apply to the standard service or significant change service. disallow deferral in either case.
            if ((listenerSettings?.DeferLocationUpdates ?? false) && CanDeferLocationUpdate)
            {
                manager.DisallowDeferredLocationUpdates();
            }
#endif

            if (listenerSettings?.ListenForSignificantChanges ?? false)
            {
                manager.StopMonitoringSignificantLocationChanges();
            }
            else
            {
                manager.StopUpdatingLocation();
            }

            listenerSettings = null;
            position         = null;

            return(Task.FromResult(true));
        }
示例#2
0
 /// This method is called as part of the transiton from background to active state.
 public override void WillEnterForeground(UIApplication application)
 {
     if (LocationManager != null)
     {
         LocationManager.StopMonitoringSignificantLocationChanges();
         LocationManager.StartUpdatingLocation();
     }
 }
示例#3
0
        public void StopIntenseLocationScanning( )
        {
            Console.WriteLine("LocationManager: STOPPING INTENSE SCANNING.");
            IntenseScanningEnabled = false;

            // when we're outside all known regions, we'll stop intense scanning so the
            // user's battery isn't completely drained
            CLLocationManager.StopMonitoringSignificantLocationChanges( );
            CLLocationManager.AllowsBackgroundLocationUpdates = false;
            CLLocationManager.StopUpdatingLocation( );
        }
示例#4
0
        public void StopLocationUpdates()
        {
            if (IsLocationUpdates)
            {
                IsLocationUpdates = false;

                if (LocMgr != null)
                {
                    LocMgr.StopUpdatingLocation();
                    locMgr.StopMonitoringSignificantLocationChanges();
                }
            }
        }
        /// <summary>
        /// Stops monitoring all regions
        /// </summary>
        public void StopMonitoringAllRegions()
        {
            if (AvailableForMonitoring())
            {
                GeofenceStore.SharedInstance.RemoveAll();

                foreach (CLCircularRegion region in locationManager.MonitoredRegions)
                {
                    locationManager.StopMonitoring(region);
                }
                locationManager.StopMonitoringSignificantLocationChanges();
                mRegions.Clear();
                mGeofenceResults.Clear();
                CrossGeofence.GeofenceListener.OnMonitoringStopped();
            }
        }
示例#6
0
        public override void Stop()
        {
            lock (_locker)
            {
                base.Stop();

#if __IOS__
                if (_significantChangePoll)
                {
                    _locationManager.StopMonitoringSignificantLocationChanges();
                }
#endif

                SensusContext.Current.CallbackScheduler.UnscheduleCallback(_pollCallback);
                _pollCallback = null;
            }
        }
示例#7
0
        public override void Stop()
        {
            lock (_locker)
            {
                base.Stop();

#if __IOS__
                if (_significantChangePoll)
                {
                    _locationManager.StopMonitoringSignificantLocationChanges();
                }
#endif

                SensusServiceHelper.Get().UnscheduleCallback(_pollCallbackId);
                _pollCallbackId = null;
            }
        }
示例#8
0
        public static Task <bool> StopTracking()
        {
            if (!IsTracking || Manager == null)
            {
                return(Task.FromResult(result: true));
            }

            IsTracking = false;

            if (CanDeferLocationUpdate)
            {
                Manager.DisallowDeferredLocationUpdates();
            }

            Manager.StopMonitoringSignificantLocationChanges();
            Manager.StopUpdatingLocation();

            return(Task.FromResult(result: true));
        }
示例#9
0
        public void PromtUserToEnableLocationService(Action callcack)
        {
            if (CLLocationManager.Status == CLAuthorizationStatus.Authorized)
            {
                return;
            }

            _onSuccessEnableLocationCallback       = callcack;
            _locationManager.AuthorizationChanged += HandleAuthorizationChanged;

            if (CLLocationManager.Status == CLAuthorizationStatus.NotDetermined)
            {
                _locationManager.StartMonitoringSignificantLocationChanges();
                _locationManager.StopMonitoringSignificantLocationChanges();
            }
            else if (
                CLLocationManager.Status == CLAuthorizationStatus.Restricted ||
                CLLocationManager.Status == CLAuthorizationStatus.Denied
                )
            {
                UIAlertView alert = new UIAlertView("Need to enable location service", "To use this feature you must enable location service in settings", null, "Ok");
                alert.Show();
            }
        }
示例#10
0
        private void MonitorLocation(UIApplicationState appState)
        {
            if (CLLocationManager.LocationServicesEnabled)
            {
                LastSentLocationTime  = new DateTime(0);
                FirstSentLocationTime = new DateTime(0);
                Console.WriteLine("MONITOR LOCATION");

                GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("app_action", "location", "monitor location", null).Build());

                LocationManager = new CLLocationManager();
                LocationManager.DesiredAccuracy = 10;
                LocationManager.PausesLocationUpdatesAutomatically = false;

                LocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
                    CLLocation currentLocation  = e.Locations[e.Locations.Length - 1];
                    DateTime   locationDateTime = DateTime.SpecifyKind(currentLocation.Timestamp, DateTimeKind.Utc);

                    double timeremaining = UIApplication.SharedApplication.BackgroundTimeRemaining;

                    Console.WriteLine("LOCATION UPDATE - Time Remaining: " + timeremaining.ToString());

                    if (LastSentLocationTime.Ticks == 0)
                    {
                        Console.WriteLine("FIRST LOCATION SENT");
                        sendLocation(currentLocation);
                        FirstSentLocationTime = locationDateTime;
                        LastSentLocationTime  = locationDateTime;
                    }
                    else
                    {
                        var diffInSeconds = (locationDateTime - LastSentLocationTime).TotalSeconds;
                        if (diffInSeconds >= 10.0)
                        {
                            Console.WriteLine("LOCATION SENT");
                            GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("app_action", "location", "location sent", null).Build());
                            sendLocation(currentLocation);
                            LastSentLocationTime = locationDateTime;
                        }

                        var diffInSecondsFromFirst = (locationDateTime - FirstSentLocationTime).TotalSeconds;
                        if (diffInSecondsFromFirst >= 120)
                        {
                            Console.WriteLine("STOP MONITOR LOCATION");
                            GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("app_action", "location", "stop monitor location", null).Build());
                            if (LocationManager != null)
                            {
                                LocationManager.StopUpdatingLocation();
                                LocationManager.StopMonitoringSignificantLocationChanges();
                            }

                            LocationManager = null;
                        }
                    }
                };


                if (appState == UIApplicationState.Active)
                {
                    LocationManager.StartUpdatingLocation();
                }
                else
                {
                    LocationManager.StartMonitoringSignificantLocationChanges();
                }
            }
            else
            {
                Console.WriteLine("Location services not enabled");
            }
        }
示例#11
0
 public void StopLocationUpdates()
 {
     _clManager.StopUpdatingLocation();
     _clManager.StopMonitoringSignificantLocationChanges();
     IsListening = false;
 }
示例#12
0
 public void OnResume()
 {
     _locationManager.StopMonitoringSignificantLocationChanges();
 }
示例#13
0
 public void StopListeningForSignificantLocationChanges()
 {
     _manager.StopMonitoringSignificantLocationChanges();
 }