Skip to content

Instantly share code, notes, and snippets.

@cheebow
Last active December 24, 2015 13:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheebow/6807538 to your computer and use it in GitHub Desktop.
Save cheebow/6807538 to your computer and use it in GitHub Desktop.
CMStepCounter Sample
#import <UIKit/UIKit.h>
#import <CoreMotion/CoreMotion.h>
@interface MYViewController : UIViewController
@property (nonatomic, strong) CMStepCounter *stepCounter;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
self.stepCounter = [[CMStepCounter alloc] init];
NSDate *now = [NSDate date];
NSDate *from = [NSDate dateWithTimeInterval:-60*60*24 sinceDate:now];
__weak typeof(self) weakSelf = self;
[self.stepCounter queryStepCountStartingFrom:from
to:now
toQueue:[NSOperationQueue mainQueue]
withHandler:^(NSInteger numberOfSteps, NSError *error) {
weakSelf.title = [@(numberOfSteps) stringValue];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment