有关ios健康记步的算法
来源:互联网 发布:mac电脑还原出厂设置 编辑:程序博客网 时间:2024/06/15 20:42
//.首先ios7以上的系统 有运动协处理器的设备 用户必须是允许读取健身数据的前提下
if ([CMStepCounterisStepCountingAvailable]) {
NSCalendar *calendar = [NSCalendarcurrentCalendar];
NSDate *now = [NSDatedate];
_dateNow = now ;
NSDateComponents *components = [calendarcomponents:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDayfromDate:now];
NSDate *startDate = [calendar dateFromComponents:components];
NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDayvalue:1toDate:startDate options:0];
[self.stepCounterqueryStepCountStartingFrom:startDate to:endDate toQueue:self.operationQueuewithHandler:^(NSInteger numberOfSteps,NSError * _Nullable error) {
NSString *text = [NSStringstringWithFormat:@"步數: %ld", (long)numberOfSteps];
//weakSelf.bu.text = (long)numberOfSteps ;
weakSelf.bu.text = [NSStringstringWithFormat:@"%ld", (long)numberOfSteps];
weakSelf.bushu = [NSStringstringWithFormat:@"%ld", (long)numberOfSteps];
// [self showHint:[NSString stringWithFormat:@"%ld", (long)numberOfSteps]];
//weakSelf.stepsLabel.text = text;
}];
self.stepCounter = [[CMStepCounteralloc] init];
[self.stepCounterstartStepCountingUpdatesToQueue:self.operationQueue
updateOn:20
withHandler:
^(NSInteger numberOfSteps,NSDate *timestamp, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
UIAlertView *error = [[UIAlertViewalloc] initWithTitle:@"提示"message:@"请允许资源家访问运动与健康"delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil,nil];
[errorshow];
}
else {
[self.stepCounterqueryStepCountStartingFrom:startDate to:endDate toQueue:self.operationQueuewithHandler:^(NSInteger numberOfSteps,NSError * _Nullable error) {
NSString *text = [NSStringstringWithFormat:@"步數: %ld", (long)numberOfSteps];
//weakSelf.bu.text = (long)numberOfSteps ;
weakSelf.bu.text = [NSStringstringWithFormat:@"%ld", (long)numberOfSteps];
weakSelf.bushu = [NSStringstringWithFormat:@"%ld", (long)numberOfSteps];
// [self showHint:[NSString stringWithFormat:@"%ld", (long)numberOfSteps]];
//weakSelf.stepsLabel.text = text;
}];
//
// NSString *text = [NSString stringWithFormat:@"步數: %ld", weakSelf.numBu +(long)numberOfSteps];
// NSDate *nowDa = [NSDate date];
// NSString *text1 = [NSString stringWithFormat:@"%ld", weakSelf.numBu +(long)numberOfSteps];
// self.bu.text = text1 ;
// self.bushu = text1 ;
// [self showHint:text];
}
});
}];
}
//開波
if ([CMMotionActivityManagerisActivityAvailable]) {
self.activityManager = [[CMMotionActivityManageralloc] init];
[self.activityManagerstartActivityUpdatesToQueue:self.operationQueue
withHandler:
^(CMMotionActivity *activity) {
dispatch_async(dispatch_get_main_queue(), ^{
});
}];
}
//5S 以下的设备 需要自己太高算法去计算
NSString * st =[[NSUserDefaultsstandardUserDefaults]objectForKey:@"bushu"];
stepCount = st.intValue ;
__weak FirstViewController *weakSelf =self;
[SOMotionDetectorsharedInstance].motionTypeChangedBlock = ^(SOMotionType motionType) {
NSString *type = @"";
switch (motionType) {
case MotionTypeNotMoving:
type =@"Not moving";
break;
case MotionTypeWalking:
type =@"Walking";
break;
case MotionTypeRunning:
type =@"Running";
break;
case MotionTypeAutomotive:
type =@"Automotive";
break;
}
};
[SOMotionDetectorsharedInstance].locationChangedBlock = ^(CLLocation *location) {
};
[SOMotionDetectorsharedInstance].accelerationChangedBlock = ^(CMAcceleration acceleration) {
};
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
[SOMotionDetectorsharedInstance].useM7IfAvailable =YES; //Use M7 chip if available, otherwise use lib's algorithm
}
[[SOMotionDetectorsharedInstance] startDetection];
[[SOStepDetectorsharedInstance] startDetectionWithUpdateBlock:^(NSError *error) {
if (error) {
NSLog(@"%@", error.localizedDescription);
return;
}
NSDate *nowD = [NSDatedate];
stepCount++;
- 有关ios健康记步的算法
- iOS 健康 计步 卡路里
- IOS -- 获取用户的健康数据的运动步数
- iOS 获取健康里的信息(步数和公里数)
- iOS 获取步数等健康信息
- iOS-获取手机健康步数,去除人为添加的数据
- iOS-获取手机健康步数,去除人为添加的数据
- iOS利用HealthKit获取健康里的步数和睡眠时间
- iOS-获取手机健康步数,去除人为添加的数据
- iOS获取健康步数从加速计到healthkit
- iOS使用HHealthKit读取修改健康步数
- iOS获取健康步数从加速计到healthkit
- iOS 健康 获取运动步数 距离 时间
- 有关“吃”的十大健康杀手
- iOS-OC-修改微信运动步数(读取和修改健康步数HealthKit)
- HealthKit 获取健康步数,去除人为添加的数据
- iOS的计步实现
- ios-步数的获取
- android设置系统时间
- php getimagesize()函数获取图片宽度高度
- 通过解析binlog,实现MySQL的flashback功能【python实现】
- 1003
- android 基础 线程sleep,join,yield
- 有关ios健康记步的算法
- 职业生涯规划案例
- 线程同步的方式和机制
- html引入css文件和js文件方式
- JAVA 笔记(二)
- 【bzoj 1616】: [Usaco2008 Mar]Cow Travelling游荡的奶牛 dp
- 第8周项目2 - 用对象数组操作长方形类
- JSP中的EL表达式(3)
- git开源库——性能优化——图片缓存