Health & Fitness

RSS for tag

Explore the technical aspects of health and fitness features, including sensor data acquisition, health data processing, and integration with the HealthKit framework.

Health & Fitness Documentation

Posts under Health & Fitness subtopic

Post

Replies

Boosts

Views

Activity

Can a particular user access other user HealthData via AppleHealthKit, Swift5, iOS
We are trying to create an IOS app where a given user wants other people to access their HealthData after they have provided relevant access. Can a particular user access other user HealthData via AppleHealthKit if the given user has provided relevant access? What level of access does the user need to be provide to incorporate this workflow.
0
0
556
Nov ’22
How to get Auto-Pause preference from the watchOS Settings?
My App with outdoor-running activity type receives HKWorkoutEvent.motionPaused und HKWorkoutEvent.motionResumed events from HKLiveWorkoutBuilderDelegate, even if the User toggled the feature off in the workout settings (Settings -> Workout -> Auto-Pause). I guess this is unexpected behavior (FB11754136), but is there a way to check the user preference from the watchOS settings? Kind regards, Josh
1
0
1.6k
Nov ’22
assuming human error on source code for "What's new in HealthKit" session
This is the copy of source code one could see on What's new in Health Kit Session: // predicate for sleep samples let remSleepStagePredicate = HKCategoryValueSleepAnalysis.predicateForSamples(.equalTo, value: .asleepREM) // create query with the designated sleepStagePredicate let queryPredicate = HKSamplePredicate.sample(type: HKCategoryType(.sleepAnalysis), predicate: remSleepStagePredicate) // Sleep Query let sleepQuery = HKSampleQueryDescriptor(predicates: [queryPredicate], sortDescriptors: []) // Run the query let sleepSamples = try async sleepQuery.result(for: healthStore) I tried to take a snaphot of the session itself, but for some reason I could not submit it with the file attached so I provided the code above. I am wondering that shouldn't it be try await, not try async on the last line of the source code? so the last line should be the code below: let sleepSamples = try await sleepQuery.result(for: healthStore) Am I mistaken, or is it a human error?
2
0
1.2k
Nov ’22
How to Get Same Average Heart Rate Value as Health App From a Workout Session ?
Hi, I am currently developing feature that is using Health Kit to get data from apple watch. I noticed that all Workout Data I created from my Apple Watch SE doesn't have metadata mentioning about average HR value, but in the Health App on workout detail report, we are able to see the "Average Heart Rate" on Related Samples. I did some research about how to get the average Heart Rate (HR) from a workout session and the answer I could find was fetching the HR samples from the workout start - end, or using Statistic Discrete Average HR query during workout session start - end. I tried to compare both average HR value from those two queries result. From many workouts I had checked, the average HR value that almost gives consistency / almost same is Discrete Collection Average HR query. But I found some issues : on some Workouts, the average HR value I get from statistic discrete average HR is not same as what shown in the Health App. On the Workout sample below, the end time shows wrong date, but in the workout graph, it shows correct end time. I noticed that the list of HR data of the "Average Heart Rate" on Related Sample section doesn't show some of HR data that has Heart Rate Context "Workout". On the Workout sample below, I tried to use discrete average HR query and HR samples query. the HR samples queries didn't give correct value of average HR. I also tried to calculate manually the average HR value from the list Heart Rate Data on the Related Samples "Average Heart Rate" only able to get average Workout HR: 83.31270358306189. Detail Sample Workout from Apple Health: "Workout Type": Running "Start Time": 3 Oct 2022 08.12.10 "End Time" : 3 Oct 2022 23:59:59 "Duration": 27m 51,96s "average HR": 86 bpm Heart Rate Samples Query : Logic: Sum all HR value and divided by the total HR data 'averageWorkoutHR': 83.31270358306189 Statistic Discrete Average HR Query 'Discrete Average:' [{ "value":85.8568822930529, "startDate":"2022-10-03T08:12:10.000+0700", "endDate":"2022-10-03T08:40:01.000+0700" }, { "value":74.33866717330343, "startDate":"2022-10-03T08:40:01.000+0700", "endDate":"2022-10-03T09:07:52.000+0700" }]' My questions are: what is the best practice to get the same average HR value as what Health app shown in the Workout Session "Average Heart Rate" on related sample section? Why Apple Health store wrong end time for the workout session? I attached here for the pictures and the json file for all the HR samples I get from the HR Samples Query HR sample Queries during workout session: workout_running_3_Oct.json Workout Sample: HR Sample Related Sample
0
1
956
Nov ’22
Heart Rate not accessible on some devices even with all the permissions
I'm developing an app for a client that provides lockscreen widgets for different categories. There are two categories that use healthkit - heart and steps. Heart shows the latest heart rate reading, and steps shows the total steps of the day. The steps widget works perfectly. But, the heart widget doesn't work on the client's phone. The widgets work perfectly on my end. I tested it on multiple devices, and it works perfectly. But, it doesn't work on the client's phone. He tested it on 2-3 devices, and it didn't work on any of them. The permissions to read heart rate are confirmed to be given. I'm in Canada, and the client is in UK. I changed the region on my phone and tried it, but that didn't change anything and the widget again worked on my devices. Now, I tried Sentry to capture the error being received. But all I am getting is this - Could not get heart rate data Optional(Error Domain=com.apple.healthkit Code=6 "Protected health data is inaccessible" UserInfo={NSLocalizedDescription=Protected health data is inaccessible}) The steps widget works perfectly. I checked Sentry, there is no other error. Now, this is the same error, we get on steps widget too when the widget tries to access health kit data when the device is locked. I have failsafes for that. But, the heart rate widget never reads any value on client's device and just gives null. This is how the widget shows on my device. These images are from the client's phone. So, the read permission for heart rate is there. The "E and A no data" on the widget is a debug statement which means that nil is received as the heart rate value. The other widget thus shows 0 which is the failsafe in these cases. Both the devices are on iOS 16.1. Have tested it on simulators too, works perfectly. Have tested it on iOS 16.0. It's just the client's devices that give these errors.
1
0
1.3k
Dec ’22
Display Health Awards in Third-Party App
I am considering developing a health/fitness app for iPhone and Apple Watch. The HealthKit documentation provides guidelines for displaying Activity Rings in a third-party app, but I could not find any information about displaying awards the user has earned. Is it possible for a third-party health/fitness app to display the user’s awards in-app, or are these accessible exclusively through the default Fitness app?
0
0
637
Nov ’22
internal healthkit error: "Unable to invalidate interval: no data source avallable"
we are seeing what appears to be an internal healthkit error appearing in our app.  not sure if it's connected, but we've mostly seen it reported on devices running ios 16.  even though our app's primary language is japanese, and in all reported occurrences the app was running in japanese, the error message itself appears in english.  searching the error string on the web yields surprisingly few results (including only two mentions on this forum that i could find, neither of which seemed relevant).  this would seem to suggest that it's coming from something deep inside healthkit, since the error message is not localized.  in all reported cases, the user had recently upgraded to a new iphone.  in most cases, the problem only occurs on the new device even though everything had been working correctly prior to the upgrade.  the error occurs when the app is unable to read step count data from healthkit. we have confirmed that the app has been granted access permissions to all health data via os settings.  we've also tried having the user toggling those settings off, then back on, rebooting the device, deleting and reinstalling the app, etc., to no avail. the error message is "Unable to invalidate interval: no data source avallable." we'd appreciate it if anyone can shed more light on this issue. thanks!
4
3
1.8k
Oct ’24
Shortcut for Taken Tablets / Medicine
Hi, I would like to have an option in shortcuts to trigger the point: Tablets / Medicine Taken. So I can use an Automation with NFC or Siri to trigger at my Medicine Box when I take it. Its a little frustrating to take out the iPhone / open the message / open the app / trigger the Button. Second is an information again when I don't take the medicine, may at a delay 1-2 hours. Thanks
1
6
2.4k
Dec ’22
Need help
Received a letter from the moderators "Hello, Thank you for your reply. During our review, we noticed that the apps under your Apple Developer Program account appear to have been created for various organizations. They share the same basic structure, format, or framework, and only vary in branding and content. Apps with shared or similar content as such are considered to be out of compliance with the Guideline 5.2.1 of the App Store Review Guidelines. To resolve the issue, these types of apps need to be submitted by the business or content owner under its own Apple Developer Program account. If you are submitting the app on behalf of a client, you should instruct your client to create its own Apple Developer Program account and submit the app under its own account. Best regards, " The situation is this. I put together an application for personal use with friends, since I do not have a developer account, I asked a friend to publish my application. But they don't want to publish it! What to do? who can help? who can explain what is the problem?
3
1
1.4k
Dec ’22
Apple health data retrieval issue with summary
In Apple health I have the data for current day & my Application also connected with Apple Health. I gave all permissions regarding the health records. Some of the user the summary query is not getting executed & no data returned from the query. Most of the users are working fine. Background fetch is also enabled for Apple Health. The user is trying to sync the data in foreground. In crashlytics I got the error "Protected health data is inaccessible". Can you please help me when this error may come.
0
1
801
Dec ’22
Error Domain=com.apple.healthkit Code=3 "Unable to invalidate interval: no data source available."
I have used below source code to get the steps from HealthKit. It's working fine many users but few users face the issue regards to get the steps from HealthKit in the our Application. After tracking the logs that issue found **: Error Domain=com.apple.healthkit Code=3 "Unable to invalidate interval: no data source available." ** Please help to know what exactly issue in the below source code. -(void) HealthKitSteps {     HKHealthStore *healthStore = [[HKHealthStore alloc] init];     NSCalendar *calendar = [NSCalendar currentCalendar];     [calendar setTimeZone:[NSTimeZone localTimeZone]];     NSDateComponents *interval = [[NSDateComponents alloc] init];     interval.hour = 2;   NSDateComponents *anchorComponents = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];     anchorComponents.hour = 0;     NSDate *anchorDate = [calendar dateFromComponents:anchorComponents];     HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; //    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"metadata.%K != YES", HKMetadataKeyWasUserEntered];     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{     HKStatisticsCollectionQuery *query = [[HKStatisticsCollectionQuery alloc] initWithQuantityType:quantityType quantitySamplePredicate:nil options:HKStatisticsOptionCumulativeSum anchorDate:anchorDate intervalComponents:interval];     // Set the results handler     query.initialResultsHandler = ^(HKStatisticsCollectionQuery *query, HKStatisticsCollection *results, NSError *error) {         if (error) {             // Perform proper error handling here             [UIUtils NSLogFunction:[NSString stringWithFormat:@"*** An error occurred while calculating the statistics: %@ ***",error.localizedDescription] dict:nil];         }         else         {             NSDate* sourceDate = [NSDate date];             NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:sourceDate];             NSDateFormatter *endDateFormatter = [[NSDateFormatter alloc] init];             [endDateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];             [endDateFormatter setTimeZone:[NSTimeZone localTimeZone]];                          NSString* localTime = [endDateFormatter stringFromDate:destinationDate];             NSDate* endDate = [endDateFormatter dateFromString:localTime];                          NSDateFormatter *objDateFormatter = [[NSDateFormatter alloc] init];             [objDateFormatter setDateFormat:@"yyyy-MM-dd"];             [objDateFormatter setTimeZone:[NSTimeZone localTimeZone]];                          NSDate *startDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:-self->diffDaysFromLastSync toDate:endDate options:0];                          NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];             [calendar setTimeZone:[NSTimeZone localTimeZone]];             NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:startDate];             [components setTimeZone:[NSTimeZone localTimeZone]];             [components setHour:0];             startDate = [calendar dateFromComponents:components];                          NSLog(@"Healthkit : startDate : %@ endDate : %@",[endDateFormatter stringFromDate:startDate],[endDateFormatter stringFromDate:endDate]);                          [results enumerateStatisticsFromDate:startDate toDate:endDate withBlock:^(HKStatistics *result, BOOL *stop) {             HKQuantity *quantity = result.sumQuantity;                 if (quantity) {                     double value = [quantity doubleValueForUnit:[HKUnit countUnit]];                     NSString *count = [NSString stringWithFormat:@"%.f",value];                     NSString *dateOfCount  = [objDateFormatter stringFromDate:[result startDate]];                     NSString* dateTime = [endDateFormatter stringFromDate:[result startDate]];                     NSLog(@"results quantity start Date %@ sum %@ Count %@",result.startDate, result.sumQuantity,count);                 }                 else                 {                     NSLog(@"results not found");                 }             }];         }     };     [healthStore executeQuery:query];     }); }
1
1
1k
Dec ’22
HealthKit: Send data from Bluetooth LE heart rate monitor to HealthKit when app is closed
I am working with a BLE peripheral that tracks heart rate. I can sync the data to HealthKit when the app is running and it is working fine. I would like to send the heart rate to HealthKit without user opening the app. It is mentioned in the documentation that the direct import of data is possible from Bluetooth LE heart rate monitors to HealthKit.  Link : https://developer.apple.com/documentation/healthkit/hksource?language=objc Any help would be greatly appreciated.
0
0
771
Jan ’23
Cannot find 'OCKSurveyTaskViewController' in scope
While implementing WWDC21's Build a research and care app(https://developer.apple.com/news/?id=jbprpg8c), an error occurred in Xcode when trying to use OCKSurveyTaskViewController and OCKSurveyTaskViewControllerDelegate. The Xcode version currently in use is version 14.2, and CareKit and ResearchKit use the main branch on GitHub as of February 1, 2023 Like the reply to the issue posted at https://github.com/carekit-apple/CareKit/issues/645, even if I try a specific version of CareKit and clean the build folder, the same situation repeats. How should i solve this?
0
0
753
Feb ’23
Can a particular user access other user HealthData via AppleHealthKit, Swift5, iOS
We are trying to create an IOS app where a given user wants other people to access their HealthData after they have provided relevant access. Can a particular user access other user HealthData via AppleHealthKit if the given user has provided relevant access? What level of access does the user need to be provide to incorporate this workflow.
Replies
0
Boosts
0
Views
556
Activity
Nov ’22
How to get Auto-Pause preference from the watchOS Settings?
My App with outdoor-running activity type receives HKWorkoutEvent.motionPaused und HKWorkoutEvent.motionResumed events from HKLiveWorkoutBuilderDelegate, even if the User toggled the feature off in the workout settings (Settings -> Workout -> Auto-Pause). I guess this is unexpected behavior (FB11754136), but is there a way to check the user preference from the watchOS settings? Kind regards, Josh
Replies
1
Boosts
0
Views
1.6k
Activity
Nov ’22
assuming human error on source code for "What's new in HealthKit" session
This is the copy of source code one could see on What's new in Health Kit Session: // predicate for sleep samples let remSleepStagePredicate = HKCategoryValueSleepAnalysis.predicateForSamples(.equalTo, value: .asleepREM) // create query with the designated sleepStagePredicate let queryPredicate = HKSamplePredicate.sample(type: HKCategoryType(.sleepAnalysis), predicate: remSleepStagePredicate) // Sleep Query let sleepQuery = HKSampleQueryDescriptor(predicates: [queryPredicate], sortDescriptors: []) // Run the query let sleepSamples = try async sleepQuery.result(for: healthStore) I tried to take a snaphot of the session itself, but for some reason I could not submit it with the file attached so I provided the code above. I am wondering that shouldn't it be try await, not try async on the last line of the source code? so the last line should be the code below: let sleepSamples = try await sleepQuery.result(for: healthStore) Am I mistaken, or is it a human error?
Replies
2
Boosts
0
Views
1.2k
Activity
Nov ’22
How to Get Same Average Heart Rate Value as Health App From a Workout Session ?
Hi, I am currently developing feature that is using Health Kit to get data from apple watch. I noticed that all Workout Data I created from my Apple Watch SE doesn't have metadata mentioning about average HR value, but in the Health App on workout detail report, we are able to see the "Average Heart Rate" on Related Samples. I did some research about how to get the average Heart Rate (HR) from a workout session and the answer I could find was fetching the HR samples from the workout start - end, or using Statistic Discrete Average HR query during workout session start - end. I tried to compare both average HR value from those two queries result. From many workouts I had checked, the average HR value that almost gives consistency / almost same is Discrete Collection Average HR query. But I found some issues : on some Workouts, the average HR value I get from statistic discrete average HR is not same as what shown in the Health App. On the Workout sample below, the end time shows wrong date, but in the workout graph, it shows correct end time. I noticed that the list of HR data of the "Average Heart Rate" on Related Sample section doesn't show some of HR data that has Heart Rate Context "Workout". On the Workout sample below, I tried to use discrete average HR query and HR samples query. the HR samples queries didn't give correct value of average HR. I also tried to calculate manually the average HR value from the list Heart Rate Data on the Related Samples "Average Heart Rate" only able to get average Workout HR: 83.31270358306189. Detail Sample Workout from Apple Health: "Workout Type": Running "Start Time": 3 Oct 2022 08.12.10 "End Time" : 3 Oct 2022 23:59:59 "Duration": 27m 51,96s "average HR": 86 bpm Heart Rate Samples Query : Logic: Sum all HR value and divided by the total HR data 'averageWorkoutHR': 83.31270358306189 Statistic Discrete Average HR Query 'Discrete Average:' [{ "value":85.8568822930529, "startDate":"2022-10-03T08:12:10.000+0700", "endDate":"2022-10-03T08:40:01.000+0700" }, { "value":74.33866717330343, "startDate":"2022-10-03T08:40:01.000+0700", "endDate":"2022-10-03T09:07:52.000+0700" }]' My questions are: what is the best practice to get the same average HR value as what Health app shown in the Workout Session "Average Heart Rate" on related sample section? Why Apple Health store wrong end time for the workout session? I attached here for the pictures and the json file for all the HR samples I get from the HR Samples Query HR sample Queries during workout session: workout_running_3_Oct.json Workout Sample: HR Sample Related Sample
Replies
0
Boosts
1
Views
956
Activity
Nov ’22
Health kit - How to Get shared health data along with my health data Programmatically
Health kit - How to Get shared health data along with my health data Programmatically
Replies
1
Boosts
0
Views
1.3k
Activity
Nov ’22
Health Kit - If i want to share my data to clinician then how to obtain the data programmatically
Health Kit - If i want to share my data to clinician then how to obtain the data programmatically
Replies
0
Boosts
0
Views
1.2k
Activity
Nov ’22
Heart Rate not accessible on some devices even with all the permissions
I'm developing an app for a client that provides lockscreen widgets for different categories. There are two categories that use healthkit - heart and steps. Heart shows the latest heart rate reading, and steps shows the total steps of the day. The steps widget works perfectly. But, the heart widget doesn't work on the client's phone. The widgets work perfectly on my end. I tested it on multiple devices, and it works perfectly. But, it doesn't work on the client's phone. He tested it on 2-3 devices, and it didn't work on any of them. The permissions to read heart rate are confirmed to be given. I'm in Canada, and the client is in UK. I changed the region on my phone and tried it, but that didn't change anything and the widget again worked on my devices. Now, I tried Sentry to capture the error being received. But all I am getting is this - Could not get heart rate data Optional(Error Domain=com.apple.healthkit Code=6 "Protected health data is inaccessible" UserInfo={NSLocalizedDescription=Protected health data is inaccessible}) The steps widget works perfectly. I checked Sentry, there is no other error. Now, this is the same error, we get on steps widget too when the widget tries to access health kit data when the device is locked. I have failsafes for that. But, the heart rate widget never reads any value on client's device and just gives null. This is how the widget shows on my device. These images are from the client's phone. So, the read permission for heart rate is there. The "E and A no data" on the widget is a debug statement which means that nil is received as the heart rate value. The other widget thus shows 0 which is the failsafe in these cases. Both the devices are on iOS 16.1. Have tested it on simulators too, works perfectly. Have tested it on iOS 16.0. It's just the client's devices that give these errors.
Replies
1
Boosts
0
Views
1.3k
Activity
Dec ’22
Display Health Awards in Third-Party App
I am considering developing a health/fitness app for iPhone and Apple Watch. The HealthKit documentation provides guidelines for displaying Activity Rings in a third-party app, but I could not find any information about displaying awards the user has earned. Is it possible for a third-party health/fitness app to display the user’s awards in-app, or are these accessible exclusively through the default Fitness app?
Replies
0
Boosts
0
Views
637
Activity
Nov ’22
internal healthkit error: "Unable to invalidate interval: no data source avallable"
we are seeing what appears to be an internal healthkit error appearing in our app.  not sure if it's connected, but we've mostly seen it reported on devices running ios 16.  even though our app's primary language is japanese, and in all reported occurrences the app was running in japanese, the error message itself appears in english.  searching the error string on the web yields surprisingly few results (including only two mentions on this forum that i could find, neither of which seemed relevant).  this would seem to suggest that it's coming from something deep inside healthkit, since the error message is not localized.  in all reported cases, the user had recently upgraded to a new iphone.  in most cases, the problem only occurs on the new device even though everything had been working correctly prior to the upgrade.  the error occurs when the app is unable to read step count data from healthkit. we have confirmed that the app has been granted access permissions to all health data via os settings.  we've also tried having the user toggling those settings off, then back on, rebooting the device, deleting and reinstalling the app, etc., to no avail. the error message is "Unable to invalidate interval: no data source avallable." we'd appreciate it if anyone can shed more light on this issue. thanks!
Replies
4
Boosts
3
Views
1.8k
Activity
Oct ’24
Shortcut for Taken Tablets / Medicine
Hi, I would like to have an option in shortcuts to trigger the point: Tablets / Medicine Taken. So I can use an Automation with NFC or Siri to trigger at my Medicine Box when I take it. Its a little frustrating to take out the iPhone / open the message / open the app / trigger the Button. Second is an information again when I don't take the medicine, may at a delay 1-2 hours. Thanks
Replies
1
Boosts
6
Views
2.4k
Activity
Dec ’22
Need help
Received a letter from the moderators "Hello, Thank you for your reply. During our review, we noticed that the apps under your Apple Developer Program account appear to have been created for various organizations. They share the same basic structure, format, or framework, and only vary in branding and content. Apps with shared or similar content as such are considered to be out of compliance with the Guideline 5.2.1 of the App Store Review Guidelines. To resolve the issue, these types of apps need to be submitted by the business or content owner under its own Apple Developer Program account. If you are submitting the app on behalf of a client, you should instruct your client to create its own Apple Developer Program account and submit the app under its own account. Best regards, " The situation is this. I put together an application for personal use with friends, since I do not have a developer account, I asked a friend to publish my application. But they don't want to publish it! What to do? who can help? who can explain what is the problem?
Replies
3
Boosts
1
Views
1.4k
Activity
Dec ’22
Apple health data retrieval issue with summary
In Apple health I have the data for current day & my Application also connected with Apple Health. I gave all permissions regarding the health records. Some of the user the summary query is not getting executed & no data returned from the query. Most of the users are working fine. Background fetch is also enabled for Apple Health. The user is trying to sync the data in foreground. In crashlytics I got the error "Protected health data is inaccessible". Can you please help me when this error may come.
Replies
0
Boosts
1
Views
801
Activity
Dec ’22
Update ring goals and custom workouts
Hey All, So sorry if this is a stupid question, but I was wondering, is there a way to update a users fitness/health ring goals via the API? Also, am I able to update and save custom workout templates via the API? Many thanks, in advance. P
Replies
0
Boosts
0
Views
601
Activity
Dec ’22
iOS16. Unable to obtain accurate segmented data。help!help!
Before iOS 16, metadata data in workoutevents can be obtained, but after iOS 16, the data in metadata is empty. How can I obtain segmented data per kilometer?
Replies
2
Boosts
0
Views
765
Activity
Dec ’22
Error Domain=com.apple.healthkit Code=3 "Unable to invalidate interval: no data source available."
I have used below source code to get the steps from HealthKit. It's working fine many users but few users face the issue regards to get the steps from HealthKit in the our Application. After tracking the logs that issue found **: Error Domain=com.apple.healthkit Code=3 "Unable to invalidate interval: no data source available." ** Please help to know what exactly issue in the below source code. -(void) HealthKitSteps {     HKHealthStore *healthStore = [[HKHealthStore alloc] init];     NSCalendar *calendar = [NSCalendar currentCalendar];     [calendar setTimeZone:[NSTimeZone localTimeZone]];     NSDateComponents *interval = [[NSDateComponents alloc] init];     interval.hour = 2;   NSDateComponents *anchorComponents = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];     anchorComponents.hour = 0;     NSDate *anchorDate = [calendar dateFromComponents:anchorComponents];     HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; //    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"metadata.%K != YES", HKMetadataKeyWasUserEntered];     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{     HKStatisticsCollectionQuery *query = [[HKStatisticsCollectionQuery alloc] initWithQuantityType:quantityType quantitySamplePredicate:nil options:HKStatisticsOptionCumulativeSum anchorDate:anchorDate intervalComponents:interval];     // Set the results handler     query.initialResultsHandler = ^(HKStatisticsCollectionQuery *query, HKStatisticsCollection *results, NSError *error) {         if (error) {             // Perform proper error handling here             [UIUtils NSLogFunction:[NSString stringWithFormat:@"*** An error occurred while calculating the statistics: %@ ***",error.localizedDescription] dict:nil];         }         else         {             NSDate* sourceDate = [NSDate date];             NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:sourceDate];             NSDateFormatter *endDateFormatter = [[NSDateFormatter alloc] init];             [endDateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];             [endDateFormatter setTimeZone:[NSTimeZone localTimeZone]];                          NSString* localTime = [endDateFormatter stringFromDate:destinationDate];             NSDate* endDate = [endDateFormatter dateFromString:localTime];                          NSDateFormatter *objDateFormatter = [[NSDateFormatter alloc] init];             [objDateFormatter setDateFormat:@"yyyy-MM-dd"];             [objDateFormatter setTimeZone:[NSTimeZone localTimeZone]];                          NSDate *startDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:-self->diffDaysFromLastSync toDate:endDate options:0];                          NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];             [calendar setTimeZone:[NSTimeZone localTimeZone]];             NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:startDate];             [components setTimeZone:[NSTimeZone localTimeZone]];             [components setHour:0];             startDate = [calendar dateFromComponents:components];                          NSLog(@"Healthkit : startDate : %@ endDate : %@",[endDateFormatter stringFromDate:startDate],[endDateFormatter stringFromDate:endDate]);                          [results enumerateStatisticsFromDate:startDate toDate:endDate withBlock:^(HKStatistics *result, BOOL *stop) {             HKQuantity *quantity = result.sumQuantity;                 if (quantity) {                     double value = [quantity doubleValueForUnit:[HKUnit countUnit]];                     NSString *count = [NSString stringWithFormat:@"%.f",value];                     NSString *dateOfCount  = [objDateFormatter stringFromDate:[result startDate]];                     NSString* dateTime = [endDateFormatter stringFromDate:[result startDate]];                     NSLog(@"results quantity start Date %@ sum %@ Count %@",result.startDate, result.sumQuantity,count);                 }                 else                 {                     NSLog(@"results not found");                 }             }];         }     };     [healthStore executeQuery:query];     }); }
Replies
1
Boosts
1
Views
1k
Activity
Dec ’22
Is it possible to access your own HealthKit data in Xcode using a free apple developer account?
I only want to read my data, and test using it in a dummy app I plan to create in Xcode on my iPhone ( not actually to submit to the AppStore) I've been told this is possible but it doesn't seem to like my account as a provisioning profile. Thank you!
Replies
0
Boosts
0
Views
545
Activity
Dec ’22
HealthKit data access
Hello, Our app currently collects the number of steps from our app users' smartwatches. (Limited to users who have insurance policy for a certain product) If the app were to no longer exist, how can I directly collect data of the users (based on personal information) from HealthKit?
Replies
0
Boosts
0
Views
585
Activity
Jan ’23
HealthKit: Send data from Bluetooth LE heart rate monitor to HealthKit when app is closed
I am working with a BLE peripheral that tracks heart rate. I can sync the data to HealthKit when the app is running and it is working fine. I would like to send the heart rate to HealthKit without user opening the app. It is mentioned in the documentation that the direct import of data is possible from Bluetooth LE heart rate monitors to HealthKit.  Link : https://developer.apple.com/documentation/healthkit/hksource?language=objc Any help would be greatly appreciated.
Replies
0
Boosts
0
Views
771
Activity
Jan ’23
Blood ketone tracking in Health Kit
Can you add a Blood Ketone tracking graph to the dashboard in HealthKit?
Replies
1
Boosts
0
Views
857
Activity
Jan ’23
Cannot find 'OCKSurveyTaskViewController' in scope
While implementing WWDC21's Build a research and care app(https://developer.apple.com/news/?id=jbprpg8c), an error occurred in Xcode when trying to use OCKSurveyTaskViewController and OCKSurveyTaskViewControllerDelegate. The Xcode version currently in use is version 14.2, and CareKit and ResearchKit use the main branch on GitHub as of February 1, 2023 Like the reply to the issue posted at https://github.com/carekit-apple/CareKit/issues/645, even if I try a specific version of CareKit and clean the build folder, the same situation repeats. How should i solve this?
Replies
0
Boosts
0
Views
753
Activity
Feb ’23