②写入数据
double step = [self.textField.text doubleValue];
HKQuantityType *stepType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKQuantity *stepQuantity = [HKQuantity quantityWithUnit:[HKUnit countUnit] doubleValue:step];
HKQuantitySample *stepSample = [HKQuantitySample quantitySampleWithType:stepType quantity:stepQuantity startDate:[self getTodayStartDate] endDate:[NSDate date]];
[self.healthStore saveObject:stepSample withCompletion:^(BOOL success, NSError * _Nullable error) {
if (error) {
NSLog(@"error: %@", error.localizedDescription);
}
dispatch_async(dispatch_get_main_queue(), ^{
self.stateLabel.text = success ? @"成功" : @"失败";
});
}];
项目中使用了HealthKit时,上架需要注意点:
Your app may not use information gained through the use of the HealthKit framework for advertising or similar services. Note that you may still serve advertising in an app that uses the HealthKit framework, but you cannot use data from the HealthKit store to serve ads.//你的应用不应该将HealthKit收集的数据用于广告或类似的服务。注意,可能在使用HealthKit框架应用中还是要服务广告,但是你不能使用HealthKit中的数据来服务广告。 You must not disclose any information gained through HealthKit to a third party without express permission from the user. Even with permission, you can only share information to a third party if they are also providing a health or fitness service to the user.// 在没有用户的明确允许下,你不能向第三方展示任何HealthKit收集的数据。即使用户允许,你也只能向提供健康或健身服务的第三方展示这些数据 You cannot sell information gained through HealthKit to advertising platforms, data brokers, or information resellers.// 你不能将HealthKit收集的数据出售给广告平台、数据代理人或者信息经销商 If the user consents, you may share his or her HealthKit data with a third party for medical research.// 如果用户允许,你可以将HealthKit数据共享给第三方用于医学研究。 You must clearly disclose to the user how you and your app will use their HealthKit data.//你必须明确说明,你和你的应用会怎样使用用户的HealthKit数据。You must also provide a privacy policy for any app that uses the HealthKit framework. You can find guidance on creating a privacy policy at the following sites://你必须为每个使用HealthKit框架的应用提供一份隐私策略。你可以在以下网站找到创建隐私策略的指导:
1、Personal Health Record model (for non-HIPAA apps): http://www.easck.com/policy-researchers-implementers/personal-health-record-phr-model-privacy-notice
2、HIPAA model (for HIPAA covered apps): http://www.easck.com/ocr/privacy/hipaa/modelnotices.html
参考文章
https://www.easck.com/documentation/healthkit#classes










