xcode - Pausing, resuming and resetting steps counting in iOS Core Motion -


i writing ios app counts steps taken user when activated using button. able count steps now, able pause , reset steps counter user request. not experienced xcode, there might easy way it. used code similar 1 available on stackoverflow:

#import "viewcontroller.h"  #import "dtstepmodelcontroller.h"  #import <coremotion/coremotion.h>    @interface viewcontroller ()    @property (weak, nonatomic) iboutlet uilabel *stepscountinglabel;  @property (nonatomic, strong) cmstepcounter *cmstepcounter;  @property (nonatomic, strong) nsoperationqueue *operationqueue;      @end    @implementation viewcontroller  {     dtstepmodelcontroller *_stepmodel;  }      - (nsoperationqueue *)operationqueue  {      if (_operationqueue == nil)      {          _operationqueue = [nsoperationqueue new];      }      return _operationqueue;  }    - (void)updatestepcounterlabelwithstepcounter:(nsinteger)countedsteps  {      self.stepscountinglabel.text = [nsstring stringwithformat:@"%ld", (long)countedsteps];  }    - (ibaction)startcountingsteps:(id)sender {      if ([cmstepcounter isstepcountingavailable])      {          self.cmstepcounter = [[cmstepcounter alloc] init];          [self.cmstepcounter startstepcountingupdatestoqueue:self.operationqueue updateon:1 withhandler:^(nsinteger numberofsteps, nsdate *timestamp, nserror *error)           {               [[nsoperationqueue mainqueue] addoperationwithblock:^{                   [self updatestepcounterlabelwithstepcounter:numberofsteps];               }];           }];      }    }

any insight, or suggessions?

i able find answer question. please note answer , previous code in question not work if you're using ios 8.2 or above apple discontinue supporting steps counting. in new ios version, can query m7 counter , save value, store it, subtract new value old one.

anyway, above code, can stop counter (pausecounter method) reset counter zero.

-(ibaction) pausecounting: (id) sender {    [self.cmstepcounter stopstepcountingupdates];  } - (ibaction) resumecounting: (id) sender {    [self.cmstepcounter startstepcountingupdatestoqueue: self.operationqueue updateon: 1 withhandler: ^ (nsinteger numberofsteps, nsdate * timestamp, nserror * error) {      [        [nsoperationqueue mainqueue] addoperationwithblock: ^ {          [self updatestepcounterlabelwithstepcounter: numberofsteps];        }      ];    }];    }


Comments

Popular posts from this blog

How to group boxplot outliers in gnuplot -

cakephp - simple blog with croogo -

bash - Performing variable substitution in a string -