Easy implementation of iOS pedometer

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.