HealthKit

The ValidicMobile library provides a simple way to read and upload data from HealthKit to Validic. VLDHealthKitManager can subscribe to specific HealthKit data types and automatically upload them to Validic in the background as new data is recorded.

Subscribing to HealthKit data updates only needs to be done once for a user. The subscriptions will be persisted across app launches in the VLDSession object. A typical use of the HealthKit component would be to create a UISwitch that adds the required subscriptions when turned on and removes them when turned off. Example:

- (IBAction)switchAction:(UISwitch *)sender {
NSArray *subscriptions = ... // HKSampleType objects
if (sender.on) {
[[VLDHealthKitManager sharedInstance] setSubscriptions:subscriptions completion:nil];
} else {
[[VLDHealthKitManager sharedInstance] setSubscriptions:@[] completion:nil];
}
}

To properly process the delivery of data in the background, the subscription observers need to be recreated immediately when the app is launched. To do this, you need to call [VLDHealthKitManager observeCurrentSubscriptions] inside your application delegate’s application:didFinishLaunchingWithOptions: callback. Example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[VLDHealthKitManager sharedInstance] observeCurrentSubscriptions];
// your application's initialization code
return YES;
}