码迷,mamicode.com
首页 > 其他好文 > 详细

M7协处理器获取运动数据

时间:2014-08-31 18:43:11      阅读:587      评论:0      收藏:0      [点我收藏+]

标签:ios   运动   

       NSObject
  NSObject大多数objective - c类层次结构的根类。
  
  CMAltimeter
  使用CMAltimeter对象启动altitude-related数据应用程序的交付。
  
  CMAttitude
  CMAttitude类的一个实例代表了测量设备的态度在一个时间点。
  
  CMLogItem
  CMLogItem类是基类的核心运动类,处理特定类型的运动事件。
  
  CMAccelerometerData
  CMAccelerometerData类的一个实例代表一个加速度计的事件。
  
  CMAltitudeData
  CMAltitudeData对象封装信息相对高度的变化。
  
  CMDeviceMotion
  CMDeviceMotion的实例封装态度的测量,转速,加速设备。
  
  CMGyroData

  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");

    }


 

M7协处理器获取运动数据

标签:ios   运动   

原文地址:http://blog.csdn.net/xietao3/article/details/38961669

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!