VLDHealthKitManager
@interface VLDHealthKitManager
VLDHealthKitManager is the Validic Mobile interface for all HealthKit operations. VLDHealthKitManager is a singleton object that must be accessed through the sharedInstance method. Like the other components of the Validic Mobile library, VLDHealthKitManager requires a valid user session in the VLDSession singleton.
VLDHealthKitManager can upload new records as they come in. Listening for new records is done by adding subscriptions for the desired sample types. This will automatically prompt the user for permission and setup background notifications for new data.
Background delivery will happen on an hourly basis if new data is available. This will result in the data being uploaded in the background throughout the day. For background delivery to be successful you must call observeCurrentSubscriptions from your application delegate’s application:didFinishLaunchingWithOptions: callback.
Notifications
When VLDHealthKitManager queues records for upload it will send an NSNotification. To listen for this
notification add an observer to the NSNotificationCenter with the constant kVLDHealthKitRecordsProcessedNotification
.
The userInfo dictionary for this notification will contain two keys, recordType
and count
. recordType will contain
an NSNumber representing the integer value of the VLDRecordType enum and count will contain the number of records that were
processed.
-
sharedInstance returns the VLDHealthKitManager singleton and should be the only way VLDHealthKitManager is accessed.
Declaration
Objective-C
+ (instancetype _Nonnull)sharedInstance;
-
Requests permission for and begins listening to HealthKit data for the specified subscriptions.
The added subscriptions are saved to the VLDSession object and persisted through the life of the session. The completion block is called once the permission screen has been dismissed or immediately if permission had been previously requested.
Declaration
Objective-C
- (void)setSubscriptions:(id)subscriptions completion:(nullable void (^)(void))completion;
Parameters
subscriptions
An array of HKSampleType objects for VLDHealthKitManager to listen for and upload
completion
A completion block that gets called once authorization for access to the sample types is completed
-
Returns the list of HKSampleTypes that are currently being listened for.
Declaration
Objective-C
- (id)subscriptions;
-
This restores the handlers for background delivery. This method must be called immediately when the app launches.
Declaration
Objective-C
- (void)observeCurrentSubscriptions;
-
Fetch historical records of the specified sets.
Declaration
Objective-C
- (void)fetchHistoricalSets:(id)historicalSets completion:(nullable void (^)(int *_Nullable, int *_Nullable))completion;
Parameters
historicalSets
The historical sets are specified as an NSArray of NSNumbers wrapping VLDHealthKitHistoricalSet enum values. Example:
@[@(VLDHealthKitHistoricalSetRoutine), @(VLDHealthKitHistoricalSetFitness)]
completion
Completion block is passed a dictionary with the count of records processed keyed by VLDRecordType enum wrapped as NSNumber. If an errors occurs, an NSError object is provided.
-
Queries HealthKit for the latest data.
Declaration
Objective-C
- (void)fetchLatestData;