With the improvement of people's living standards, coupled with the rapid development of mobile technology, more and more software into the health industry, pedometer is used to record the personal movement of a very good technology. This period of time out of curiosity about this technology, learn to learn the steps of the implementation process.
There are two ways to implement the pedometer, (1), directly call the HealthKit framework to obtain Apple's health application data. (2) Speed sensor motion sensor \ Accelerometer \ Accelerator (Motion/accelerometer sensor)
(1) HealthKit this way is simple and rough, but there are corresponding drawbacks, the framework to obtain the data seems to be 1 hours an update, if your software is to obtain real-time data, the implementation of this method is not the best choice.
(2) based on the Coremotion framework, let's look at several sensors
motion sensor \ Acceleration sensor \ Accelerometer (Motion/accelerometer sensor)Ambient light sensor (Ambient)Distance Sensors (Proximity sensor)magnetometer Sensors (magnetometer sensor)internal temperature sensor (Internal temperature sensor)Humidity Sensors (moisture sensor)Gyroscope (Gyroscope)
In IOS8 and above we can use the Cmpedometer class to get information about walking (steps, distance, upstairs, downstairs, current speed, etc.).
Whether the current device can get the number of steps
+ (BOOL) isstepcountingavailable;
Whether the current device can get the distance
+ (BOOL) isdistanceavailable;
Whether the current device can get the number of floors up and down
+ (BOOL) isfloorcountingavailable;
Whether the current device can get speed (s/m)
+ (BOOL) ispaceavailable
Whether the current device can get rhythm
+ (BOOL) iscadenceavailable
Search for information about walking based on start and end times
-(void) Querypedometerdatafromdate: (nsdate) Start toDate: (nsdate) End Withhandler: (Cmpedometerhandler) handler;
Monitoring of step changes from a certain moment
-(void) Startpedometerupdatesfromdate: (NSDate *) Start Withhandler: (Cmpedometerhandler) handler;
Stop monitoring the change of steps
-(void) stoppedometerupdates;
The corresponding method is best placed in a single case, using the corresponding method in the singleton we can obtain the data we want to obtain.
Easy implementation of iOS pedometer