Last active
December 24, 2015 13:48
-
-
Save cheebow/6807538 to your computer and use it in GitHub Desktop.
CMStepCounter Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import <CoreMotion/CoreMotion.h> | |
@interface MYViewController : UIViewController | |
@property (nonatomic, strong) CMStepCounter *stepCounter; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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