简单的计步器实现
2016-08-10 21:08
260 查看
#import "ViewController.h" #import <CoreMotion/CoreMotion.h> @interface ViewController () @property (nonatomic, strong) CMStepCounter *conter; @property (weak, nonatomic) IBOutlet UILabel *stepLabel; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 1、判断计步器是否可用 if (![CMStepCounter isStepCountingAvailable]) {return;} // 2、开始计步 [self.conter startStepCountingUpdatesToQueue:[NSOperationQueue mainQueue] updateOn:5 withHandler:^(NSInteger numberOfSteps, NSDate * _Nonnull timestamp, NSError * _Nullable error) { self.stepLabel.text = [NSString stringWithFormat:@"一共走了%ld步", numberOfSteps]; }]; } - (CMStepCounter *)conter{ if (_conter == nil) { _conter = [[CMStepCounter alloc] init]; } return _conter; }
效果图:
相关文章推荐
- ios 计步器的简单实现
- 简单实现[BCB5]:键盘全局钩子[Hook],监视多进程键盘操作。
- XML 简单接口 (SAX2)用Visual Basic 实现的示例
- 简单实现Crystal Report的动态加载
- 跨域名的Cookie实现---简单另类的实现方法
- 用NUnit2.1简单实现.net的测试驱动开发(TDD)
- 内容分页简单实现代码及祥解(C#)
- Dhtml+Js算法:5个小球运动的简化版,变通实现更简单的飞行的图片
- 打印的简单实现,以及更改打印设置
- Editplus + Zend Encoder实现简单PHP源码加密IDE环境
- 一个简单聊天室的两种实现 (fcntl 和 select)
- http断点续传简单实现(java)
- 自己如何实现简单的http服务器
- 简单的在线升级的实现方法
- 简单分析用SPI实现防火墙
- 初学者看过来:简单谈谈 C/C++ 递归的思想,实现,以及和循环的关系。
- MySql实现简单的注册登录(易语言)
- 一个简单的菜单按钮的实现
- Dhtml:用ondrag事件简单的实现鼠标拖动物件.
- Web报表打印·简单实现·(一)