IOS teach you to modify the number of steps (based on Healthkit)

Recently, see glutinous rice powder write iOS teach you how to modify the WeChat step, while the May Day holiday, also want to play WeChat movement steps, a circle of friends occupied cover, loaded with force, but that the authors are used in some of the more in-depth knowledge based on reverse engineering, but also to meet iPhone mobile phone jailbreak, I like this small rookie, his iPhone is always the first time to update the system temporarily unable to escape. As the saying goes, all roads lead to Rome, you will shift under the apple healthkit, can change the number at the end of micro walk again


Glutinous rice powder scheme based on the application of reverse engineering in WeChat is directly found in the header file, the WCDeviceStepObject class which has m7StepCount properties, very conspicuous hkStepCount, a guess attribute is used to record the number of steps and then direct motion, the preparation of Tweak.xm, get modified m7StepCount method that returns a movement step number directly, movement you can change your WeChat step number. Of course, the glutinous rice flour to write this article intended by a hot, put everyone into the field of reverse engineering. And I write this article, though also used the same concept, but the focus is not the same and glutinous rice powder, because I did not escape on hand the mobile phone, the understanding of the reverse engineering is not deep enough, so I this article is mainly studying Apple’s healthKit framework, through various third party app and apple health applications between data To achieve a variety of health data (including but not limited to the number of steps) in third party applications and apple health applications between the read and write


  • Non jailbreak Apple phone (of course, the jailbreak is OK), iOS 8 or more, because more than iOS8 apple health applications
  • Apple certificate, when creating app ID must be HealthKit, told apple that you want to use healthKit.
    IOS teach you to modify the number of steps (based on Healthkit)


  • What is HealthKit
    simply, HealthKit is iOS8, apple used to generate, store, query a variety of API health data, including fitness data iPhone itself created, or third party app to create health data can be read and query through the API. The HealthKit can also be used as a a unified database of health data iPhone, read the same health data on the mobile phone without app are directly facing the healthKit, by HealthKit unified management, to achieve the iOS health data interaction between different applications. So, WeChat (including QQ or other third party app) movement step number so, the essence is through the HealthKit to read, and we only need to create a app (of course, I am here only the development environment), request permission to write to the HealthKit data, add motion The number of steps (including QQ, WeChat or other third party app) through the HealthKit read the movement step of our health data in the mobile phone number, the number of steps of natural movement can be read by us to modify. Of course, the health data of healthKit which contains a variety of all kinds, including the number of steps, sleep, exercise distance, calories, blood pressure and so on. To view these data is very simple, open health applications iPhone inside Apple’s own, very intuitive display of our health data.
    IOS teach you to modify the number of steps (based on Healthkit)
    iPhone health applications
  • The framework of HealthKit HKUnit: due to health data including a variety of data types, HealthKit is the unified standards of these data, including HKUnit Mass, Length, Volume, Pressure, Time, Energy, Temperature, Electrical, Conductance, Scalar and other data types. [HKUnit countUnit] 2.HKQuantity: by HKUnit data type, the quantity we mathematically converted into HealthKit HKQuantity [HKQuantity quantityWithUnit:[HKUnit data. *stepQuantityConsumed = countUnit] doubleValue:stepNum]; quantityWithUnit:poundUnit doubleValue:weight];

3.HKObjectType: type of health data, including the number of steps, heart rate, calories and so on (see figure below).

IOS teach you to modify the number of steps (based on Healthkit)
common HKQuantityType

in addition, according to the type, HKQuantityType can be subdivided into the following:

  • HKCharacteristicType: is generally used to indicate those health data are usually not changed with the time of the type, apple provides three: biological sex, blood type and birthdate, the data of third party app can’t create, can only be read from HealthKit store.
  • HKCategoryType: is used to represent categories, in iOS, only one, sleep analysis, represents the quality of sleep categories
  • HKQuantityType: in addition to the above two types of other health data types.
    IOS teach you to modify the number of steps (based on Healthkit)
  • HKObjectType are generally created according to the identifier (nullable HKQuantityType) + quantityTypeForIdentifier: (NSString) identifier;
    (nullable + HKCategoryType) categoryTypeForIdentifier: (NSString) identifier;
    (nullable + HKCharacteristicType) characteristicTypeForIdentifier: (NSString) identifier;

4.HKObject: has a data type, naturally there are corresponding data objects

IOS teach you to modify the number of steps (based on Healthkit)
  • The following code is how to create a movement step number HKObject example NSDate endDate = [NSDate date]
    ; NSDate startDate = [NSDate dateWithTimeInterval:-300 sinceDate:endDate];
    HKQuantity stepQuantityConsumed = [HKQuantity quantityWithUnit:[HKUnit countUnit] doubleValue:stepNum];
    HKQuantityType stepConsumedType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];

5.HKHealthStore:healthKit manager, used to link to the database, save and query data, must be held in the app (should be long lived). Similar to the following operations are HKHealthStore object method

- (void) saveObject: (HKObject) object (withCompletion: (void ^ (BOOL) success, NSError __nullable error completion; 
)) - (void) executeQuery: (HKQuery) query;
(void) deleteObject: (HKObject) object (withCompletion: (void ^ (BOOL) success, NSError * __nullable error)) completion;

6.HKQuery:healthKit data query

@method initWithSampleType:predicate:limit:sortDescriptors:resultsHandler:
@abstract! Returns a query that will retrieve HKSamples matching the given predicate.
@param sampleType The type of sample to retrieve.
@param predicate The predicate which samples should match.
@param limit The maximum number of samples to return. Pass HKObjectQueryNoLimit for no limit.
@param sortDescriptors The sort descriptors to use to order the resulting samples.
@param resultsHandler The block to invoke with results when the query has finished executing. /
- (instancetype) in ItWithSampleType: (HKSampleType) sampleType
predicate: (nullable NSPredicate) predicate
limit: (NSUInteger) limit
sortDescriptors: (nullable NSArray< NSSortDescriptor *> sortDescriptors (resultsHandler:)
(void ^ (HKSampleQuery) query, NSArray< __kindof HKSample *> __nullable results, NSError __nullable error)) resultsHandler;

The HKQuery method can see above, including various types of data query, conditions, screening, sorting, frequency and so on, there is no detailed said, there is a need to know more about yourself, simply write a number of examples of query motion:

[self fetchSumOfSamplesTodayForType:stepType unit:[HKUnit countUnit] completion:^ (double stepCount, NSError error) {
NSLog (@%f, stepCount);
dispatch_async (dispatch_get_main_queue),
_readStepLabel.text (^{= [NSString stringWithFormat:@%.f, stepCount];
(void) fetchSumOfSamplesTodayForType: (HKQuantityType) quantityType unit: (HKUnit) unit completion: (void (^) (double, NSError)) {
NSPredicate = [self completionHandler predicate predicateForSamplesToday];
HKStatisticsQuery query = [[HKStatisticsQuery alloc] initWithQuantityType:quantityType quantitySamplePredicate:predicate options:HKS TatisticsOptionCumulativeSum completionHandler:^ (HKStatisticsQuery query, HKStatistics result, NSError error) {
HKQuantity sum = [result sumQuantity];
if (completionHandler) {
double value = [sum doubleValueForUnit:unit];
completionHandler (value, error);

[self.healthStore executeQuery:query]}]};

Hands to change the number of steps

The front briefly introduces the framework of healthKit whole, health data to modify the WeChat or other third party app, only need to modify the apple HKHealthStore data can be, should be third app is read HKHealthStore data. A simple steps:
first get permission to read, get permission to read after moving steps HKHealthStore. data is written to the third party application will automatically use HKHealthStore to update the data, is so simple.

  • The packing to the real machine, authorization after adding IOS teach you to modify the number of steps (based on Healthkit)
    IMG_3796.PNG step number
  • Add successful
    IOS teach you to modify the number of steps (based on Healthkit)
  • Real time sync to QQ’s health rankings
IOS teach you to modify the number of steps (based on Healthkit)
  • QQ health every 10 thousand steps, you can donate 10 thousand dollars for a step to do public service, up to a day to donate 3 fast, this is my biggest harvest this gadget, if you are lucky enough to see, want to do something for the public, nothing was more here in QQ the number of steps it engages in the public welfare donation
    IOS teach you to modify the number of steps (based on Healthkit)
  • However, I found that the total number of WeChat is not to read the HKHealthStore step directly so simple, I add a number of steps WeChat will not sync, I studied under iOS9, add data, iOS will automatically help us to add a data source, we can also add their own equipment information. The following figure:
    I think it should be the last WeChat brush movement step number of the situation is more serious, WeChat has taken some measures, most likely WeChat is not directly read the number of steps and the total movement, first determine the source of the data, the number of steps is not WeChat approved equipment and iPhone’s own motion processor records, WeChat will not be synchronized, so that we my app just write data to change the micro walking hundreds of failed, it seems like to WeChat, or the need to go to the direction of reverse engineering.
IOS teach you to modify the number of steps (based on Healthkit)


Although there is no successful change in the number of steps to achieve WeChat, but, I think, the results are not important, it is important that we learn HealthKit, harvest, understand the principle

Finally, although this is very simple, I put the Demo address to put it, Demo apple Healthkit is the original Demo based on the number of steps to modify the function of adding.HealthKitDemo