CMPedometer pedometer; // since iOS 8.0

		public MotionPrivacyManager ()
		{
			if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
				pedometer = new CMPedometer ();
				motionStatus = CMPedometer.IsStepCountingAvailable ? "Available" : "Not available";
			} else {
				stepCounter = new CMStepCounter ();
				motionManger = new CMMotionManager ();
				motionStatus = motionManger.DeviceMotionAvailable ? "Available" : "Not available";
			}
		}
Exemplo n.º 2
0
        CMPedometer pedometer;         // since iOS 8.0

        public MotionPrivacyManager()
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                pedometer    = new CMPedometer();
                motionStatus = CMPedometer.IsStepCountingAvailable ? "Available" : "Not available";
            }
            else
            {
                stepCounter  = new CMStepCounter();
                motionManger = new CMMotionManager();
                motionStatus = motionManger.DeviceMotionAvailable ? "Available" : "Not available";
            }
        }
 public IObservable <int> WhenReadingTaken()
 => this.stepOb ??= Observable.Create <int>(ob =>
 {
     var scm = new CMStepCounter();
     scm.StartStepCountingUpdates(NSOperationQueue.CurrentQueue ?? new NSOperationQueue(), 1, (steps, timestamp, error) =>
                                  ob.OnNext((int)steps)
                                  );
     return(() =>
     {
         scm.StopStepCountingUpdates();
         scm.Dispose();
     });
 })
 .Publish()
 .RefCount();
Exemplo n.º 4
0
        public void ForceUpdate()
        {
            //If the last reset date wasn't today then we should update this.
            if (_resetTime.Date.Day != DateTime.Now.Date.Day)
            {
                _resetTime = DateTime.Today; //Forces update as the day may have changed.
            }

            NSDate sMidnight = Helpers.DateHelpers.DateTimeToNSDate(_resetTime);

            _queue = _queue ?? NSOperationQueue.CurrentQueue;
            if (_stepCounter == null)
                _stepCounter = new CMStepCounter();

            _stepCounter.QueryStepCount(sMidnight, NSDate.Now, _queue, DailyStepQueryHandler);
        }
Exemplo n.º 5
0
 public IObservable <int> WhenReadingTaken()
 {
     this.stepOb = this.stepOb ?? Observable.Create <int>(ob =>
     {
         var scm = new CMStepCounter();
         scm.StartStepCountingUpdates(NSOperationQueue.CurrentQueue, 10, (steps, timestamp, error) =>
         {
         });
         return(() =>
         {
             scm.StopStepCountingUpdates();
             scm.Dispose();
         });
     });
     return(this.stepOb);
 }
Exemplo n.º 6
0
            public void ForceUpdate()
            {
                //If the last reset date wasn't today then we should update
                if (_resetTime.Date.Day != DateTime.Now.Date.Day)
                {
                    _resetTime = DateTime.Today; //Forces update as the day may have changed.
                }

                NSDate sMidnight = DateHelpers.DateTimeToNSDate(_resetTime);

                _queue = _queue ?? NSOperationQueue.CurrentQueue;
                if (_stepCounter == null)
                {
                    _stepCounter = new CMStepCounter();
                }

                _stepCounter.QueryStepCount(sMidnight, NSDate.Now, _queue, DailyStepQueryHandler);
            }
Exemplo n.º 7
0
        public void ForceUpdate()
        {
            //If the last reset date wasn't today then we should update this.
            if (_resetTime.Date.Day != DateTime.Now.Date.Day)
            {
                _resetTime = DateTime.Today; //Forces update as the day may have changed.
            }

            NSDate sMidnight = DateTime.SpecifyKind(_resetTime, DateTimeKind.Utc);

            if (_queue == null)
            {
                _queue = NSOperationQueue.CurrentQueue;
            }
            if (_stepCounter == null)
            {
                _stepCounter = new CMStepCounter();
            }

            _stepCounter.QueryStepCount(sMidnight, NSDate.Now, _queue, DailyStepQueryHandler);
        }
 void RequestMotionAccess()
 {
     stepCounter = new CMStepCounter();
     stepCounter.QueryStepCount(
         NSDate.FromTimeIntervalSinceNow(-60 * 60 * 24),
         NSDate.Now,
         NSOperationQueue.MainQueue, ((steps, error) => {
         if (error != null && error.Code == (int)CMError.MotionActivityNotAuthorized)
         {
             motionStatus = "Not Authorized";
             UpdateStatus();
         }
         else
         {
             motionStatus = "Available";
             var stepMsg = String.Format("You have taken {0} steps in the past 24 hours", steps);
             InvokeOnMainThread(() => {
                 stepsMessage.Text = stepMsg;
                 UpdateStatus();
             });
         }
     }));
 }