-
-
Save max6363/4945c8172805c69c4459b149f5974009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Write Steps | |
*/ | |
- (void)writeSteps:(NSInteger)steps | |
startDate:(NSDate *)startDate | |
endDate:(NSDate *)endDate | |
withFinishBlock:(void (^)(NSError *error))finishBlock | |
{ | |
// write steps | |
// quantity type : steps | |
HKQuantityType *stepsQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; | |
// generate count unit | |
HKUnit *unit = [HKUnit countUnit]; | |
// generate quantity object with step count value | |
HKQuantity *quantity = [HKQuantity quantityWithUnit:unit doubleValue:steps]; | |
// generate quantity sample object | |
HKQuantitySample *sample = [HKQuantitySample quantitySampleWithType:stepsQuantityType quantity:quantity startDate:startDate endDate:endDate]; | |
// save sample object using health-store object | |
[self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError * _Nullable error) { | |
NSLog(@"Saving steps to healthStore - success: %@", success ? @"YES" : @"NO"); | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
finishBlock(error); | |
}); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment