iPhone计步器
2016-02-08 20:37
381 查看
// // ViewController.m #import "ViewController.h" #import <CoreMotion/CoreMotion.h> @interface ViewController () /** 计步器对象 */ @property (nonatomic, strong) CMStepCounter *counter; @property (weak, nonatomic) IBOutlet UILabel *stepLabel; @end @implementation ViewController #pragma mark - 懒加载代码 - (CMStepCounter *)counter { if (_counter == nil) { _counter = [[CMStepCounter alloc] init]; } return _counter; } - (void)viewDidLoad { [super viewDidLoad]; // 1.判断计步器是否可用 if (![CMStepCounter isStepCountingAvailable]) { NSLog(@"计步器不可用"); return; } // 2.开始计步 [self.counter startStepCountingUpdatesToQueue:[NSOperationQueue mainQueue] updateOn:5 withHandler:^(NSInteger numberOfSteps, NSDate *timestamp, NSError *error) { if (error) return; self.stepLabel.text = [NSString stringWithFormat:@"您一共走了%ld步", numberOfSteps]; }]; } @end
相关文章推荐
- bzoj1864 三色二叉树
- 装饰器与函数的多层嵌套
- AngularJS中的http拦截
- ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置
- 【小白的CFD之旅】03 老蓝
- hdu1272 小希的迷宫
- bzoj4318 OSU!
- KMP
- Linux下安装webstorm
- ANDROID_MARS学习笔记_S01_006ImageView
- 功能测试(二)软件的易用性
- 内存中的堆与栈到底是怎么回事?
- 三篇IMO的文章
- 为什么过去这么久,我还没谈恋爱
- hdu 5623 KK's Number(dp)
- MIC编程
- HDU 3397 Sequence operation(线段树)
- MIC编程
- Struts2配置问题
- poj 2796 Feel Good 单调栈/dp