CMGyroData类的一个实例包含一个测量装置的旋转速度。
CMMagnetometerData
CMMagnetometerData类的实例封装的磁场测量设备的磁强计。
CMMotionActivity
CMMotionActivity类包含一个运动的数据更新事件。
CMMotionActivityManager
运动CMMotionActivityManager类提供了访问数据存储设备。
CMMotionManager
CMMotionManager对象是通往运动iOS提供的服务。
CMPedometer
使用CMPedometer对象获取pedestrian-related数据。
CMPedometerData
CMPedometerData对象封装信息用户步行的距离。
CMStepCounter
CMStepCounter类提供了访问用户已经采取措施的数量和设备。
CMStepCounter类提供了访问用户已经采取措施的数量和设备。信息收集与适当的内置的硬件和存储设备上,这样您就可以运行查询来确定用户的最近的身体活动。你用这个类来收集当前步骤数据和历史数据。(将在8.0之后有所更改,升级时要注意)
使用CMPedometer对象获取pedestrian-related数据。你使用一个计步器对象检索步骤数和其他信息距离和地板的数量提升或下降。计步器对象管理缓存的历史数据可以查询或要求实时更新的数据处理。使用一个计步器对象,创建这个类的一个实例并调用适当的方法。使用queryPedometerDataFromDate:迄今为止:withHandler:方法来检索数据,已经聚集。实时更新,使用startPedometerUpdatesFromDate:withHandler:方法开始事件处理程序提供的交付。(8.0开始支持)
CMPedometerData对象封装信息用户步行的距离。你不自己创建这个类的实例。相反,您使用CMPedometer对象请求计步器的数据系统。为每个请求的数据打包成这个类的一个实例并交付给你注册的处理程序计步器对象。(8.0开始支持)
/* * CMStepCounter * * Discussion: * CMStepCounter allows access to the approximate number of steps a user has taken * with a device. Steps can be retrieved in one of two ways: * * 1. Via a query specifying a time range from which the approximate number of steps is * tabulated and returned. (See queryStepCountStartingFrom:to:toQueue:withHandler) * * 2. By providing a queue and a block to startStepCountingUpdatesToQueue:withHandler, * step count updates will be provided on a best effort basis. Each update will return a * monotonically increasing number of steps counted since * startStepCountingUpdatesToQueue:withHandler was called and a timestamp * associated with the latest stepcount determination. Step count updates can be stopped * by either calling stopStepCountingUpdates or upon CMStepCounter deallocation. * */ NS_CLASS_AVAILABLE(NA,7_0) @interface CMStepCounter : NSObject /* * isStepCountingAvailable * * Discussion: * Determines whether the device supports step counting. */ + (BOOL)isStepCountingAvailable; /* * queryStepCountStartingFrom:to:toQueue:withHandler * * Discussion: * Queries for the approximate number of steps taken in the given time range, for up to 7 days. * The step count returned is computed from a system wide history that is continuously being * collected in the background. The result is returned to the handler/queue specified. */ - (void)queryStepCountStartingFrom:(NSDate *)start to:(NSDate *)end toQueue:(NSOperationQueue *)queue withHandler:(CMStepQueryHandler)handler; /* * startStepCountingUpdatesToQueue:withHandler * * Discussion: * Starts a series of continuous step counting updates to the handler on the designated queue. For each * update, the app will receive the total step count since this method was called (this includes * subsequent calls) and the timestamp associated with the latest determination. If the app is backgrounded * and resumed at a later time, the app will receive all of the steps counted during the background * period in the very next update. The handler will be called when the number of steps (as defined by * the user) has been detected on a best effort basis. */ - (void)startStepCountingUpdatesToQueue:(NSOperationQueue *)queue updateOn:(NSInteger)stepCounts withHandler:(CMStepUpdateHandler)handler; /* * stopStepCountingUpdates * * Discussion: * Stops step counting updates. Upon deallocation of CMStepCounter, this function will be * automatically invoked if updates are still active and stopStepCountingUpdates has not been * called. */ - (void)stopStepCountingUpdates; @end
以下是代码的应用
UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 568/2)]; [label setBackgroundColor:[UIColor grayColor]]; label.textColor =[UIColor redColor]; label.textAlignment = NSTextAlignmentCenter; [self.view addSubview:label]; if ([CMStepCounter isStepCountingAvailable]) { NSLog(@"isStepCountingAvailable!!!"); NSOperationQueue *queueStep = [[NSOperationQueue alloc] init] ; //20步数,更新一次 [_cmStepCounter startStepCountingUpdatesToQueue:queueStep updateOn:20 withHandler:^(NSInteger numberOfSteps, NSDate *timestamp, NSError *error) { NSLog(@"numberOfSteps==%ld,timestamp==%@",(long)numberOfSteps,timestamp); _steps = numberOfSteps; label.text = [NSString stringWithFormat:@"%ld",_steps]; }]; }else{ NSLog(@"isNOT StepCountingAvailable"); }
- (IBAction)doSomeThingsAction:(id)sender { __block NSInteger stepsNumber = 0; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *tempDate = [dateFormatter dateFromString:@"2014-08-31 20:20:20"]; NSOperationQueue *queueStep = [[NSOperationQueue alloc] init] ; [_stepManager queryStepCountStartingFrom:tempDate to:[NSDate date] toQueue:queueStep withHandler:^(NSInteger numberOfSteps, NSError *error) { if (!error) { stepsNumber = numberOfSteps; dispatch_async(dispatch_get_main_queue(), ^{ self.countLabel.text = [NSString stringWithFormat:@"%ld",stepsNumber]; }); }else{ NSLog(@"%@",error); } }]; [_activityManager queryActivityStartingFromDate:tempDate toDate:[NSDate date] toQueue:queueStep withHandler:^(NSArray *activities, NSError *error) { if (!error) { dispatch_async(dispatch_get_main_queue(), ^{ CMMotionActivity *tempActivity = [activities objectAtIndex:0]; NSLog(@"%@",tempActivity); }); }else{ NSLog(@"%@",error); } }]; }