源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

超精准的iOS计步器实现代码

  • 时间:2021-01-19 09:35 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:超精准的iOS计步器实现代码
本文实例为大家分享了iOS计步器实现代码,供大家参考,具体内容如下
#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;
}
效果图: [img]http://files.jb51.net/file_images/article/201611/20161122155732116.jpg?20161022155743[/img] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部