BEHealthKit 1.11
A HealthKit plugin for Unity
Loading...
Searching...
No Matches
Properties | Instance Methods | Class Methods | List of all members
BEHealthKit Class Reference

Handles HealthKit requests from Unity.

Properties

HKHealthStore * healthStore
 The HKHealthStore object.
 
NSString * controllerName
 name of the GameObject to send messages to
 
BEPedometerpedometer
 The BEPedometer object.
 
NSDictionary * longRunningQueries
 keeps track of long-running queries
 

Instance Methods

(int) - authorizationStatusForType:
 returns the authorization status for the given data type.
 
(void) - authorizeHealthKitToRead:write:completion:
 brings up the system health data authorization panel.
 
(void) - errorOccurred:
 Sends an error back to Unity.
 
(HKUnit *) - defaultUnitForSampleType:
 Returns the default unit for a sample type.
 
(void) - addLongRunningQuery:forType:
 Registers a long-running query for a sample type.
 
(void) - readHealthRecords:resultsHandler:
 read clinical records
 
(void) - generateDummyData
 generates dummy data for all authorized data types.
 
(void) - readSamples:fromDate:toDate:resultsHandler:
 read quantity, category or correlation samples.
 
(void) - readCharacteristic:resultsHandler:
 read a characteristic.
 
(void) - readSamplesForWorkoutActivity:fromDate:toDate:resultsHandler:
 read workout samples
 
(void) - readStatisticsForQuantityType:predicate:options:resultsHandler:
 perform a statistics query
 
(void) - readStatisticsCollectionForQuantityType:predicate:options:anchorDate:intervalComponents:resultsHandler:
 read health statistics collection
 
(void) - readDocumentOfType:predicate:limit:sortDescriptors:includeDocumentData:resultsHandler:
 read health document
 
(void) - beginBackgroundObserverQuery:
 begins a background observer query
 

Class Methods

(instancetype) + sharedHealthKit
 returns the shared BEHealthKit object
 

Method Documentation

◆ addLongRunningQuery:forType:

- (void) addLongRunningQuery: (HKQuery *) query
forType: (HKSampleType *) sampleType 

This is used by the plugin to keep track of observer queries.

Parameters
queryThe query in question.
sampleTypeThe sample type the query is for.

◆ authorizationStatusForType:

- (int) authorizationStatusForType: (NSString *) dataTypeString
Parameters
dataTypeStringHealthKit datatype identifiers to query.

◆ authorizeHealthKitToRead:write:completion:

- (void) authorizeHealthKitToRead: (NSArray *) readIdentifiers
write: (NSArray *) writeIdentifiers
completion: (void(^)(bool success, NSError *error)) completion 

Wrapper around the HealthKit -requestAuthorizationToShareTypes:readTypes:completion method.

Parameters
readIdentifiersarray of HealthKit datatype identifiers to read.
writeIdentifiersarray of HealthKit datatype identifiers to write.
completioncalled after the user responds to the request. If success is false, error contain information about what went wrong, otherwise it will be set to nil.

◆ beginBackgroundObserverQuery:

- (void) beginBackgroundObserverQuery: (HKQuantityTypeIdentifier) identifierString

Begins an HKAnchoredObjectQuery HKDocumentQuery for the specified data type.

Parameters
identifierStringthe data type

Provided by category BEHealthKit(read).

◆ defaultUnitForSampleType:

- (HKUnit *) defaultUnitForSampleType: (HKSampleType *) sampleType

I try to be somewhat intelligent about this (temperature, for example, will be returned in the device's locale, so you don't need to worry about converting it before displaying to the user. That said, if you want to change some of these defaults this is the place to do it. Will return nil if there is no default unit, but this shouldn't happen.

Parameters
sampleTypeThe sample type in question. Can be any sample type supported by HealthKit.

◆ errorOccurred:

- (void) errorOccurred: (NSError *) error

Converts the error to XML (See NSError+XML.h), and calls ErrorOccurred() on the HealthStore GameObject.

Parameters
errorthe error.

◆ readCharacteristic:resultsHandler:

- (void) readCharacteristic: (HKCharacteristicType *) characteristic
resultsHandler: (void(^)(id result, NSError *error)) resultsHandler 

Characteristics are things that don't change over time, like blood type or birth date.

Parameters
characteristicThe characteristic to read.
resultsHandlerCalled when the query finishes executing. If unsuccessful, error contains information about what went wrong, otherwise it will be set to nil.

Provided by category BEHealthKit(read).

◆ readDocumentOfType:predicate:limit:sortDescriptors:includeDocumentData:resultsHandler:

- (void) readDocumentOfType: (HKDocumentType *) documentType
predicate: (NSPredicate *) predicate
limit: (NSUInteger) limit
sortDescriptors: (NSArray<NSSortDescriptor *> *) sortDescriptors
includeDocumentData: (BOOL) includeDocumentData
resultsHandler: (void(^)(id result, BOOL done, NSError *error)) resultsHandler 

A query that returns a snapshot of all matching documents currently saved in the HealthKit store. See HKDocumentQuery.

Parameters
documentTypeCurrently, only HKDocumentTypeIdentifierCDA is supported.
predicatea predicate that limits the results of the query
limitthe maximum number of documents to return
sortDescriptorsan array of sort decsriptors
includeDocumentDatasend true to include all document data. send false to just return a summary.
resultsHandlerCalled when the query finishes executing. If unsuccessful, error contains information about what went wrong, otherwise it will be set to nil.

Provided by category BEHealthKit(read).

◆ readHealthRecords:resultsHandler:

- (void) readHealthRecords: (HKSampleType *) sampleType
resultsHandler: (void(^)(id result, NSError *error)) resultsHandler 

A streamlined method to perform sample queries on clinical types.

Parameters
sampleTypethe type of sample to read.
resultsHandlerCalled when the query finishes executing. If unsuccessful, error contains information about what went wrong, otherwise it will be set to nil.

Provided by category BEHealthKit(clinicalRecords).

◆ readSamples:fromDate:toDate:resultsHandler:

- (void) readSamples: (HKSampleType *) sampleType
fromDate: (NSDate *) startDate
toDate: (NSDate *) endDate
resultsHandler: (void(^)(NSArray *results, NSError *error)) resultsHandler 

Executes a query with -initWithSampleType:predicate:limit:sortDescriptors:resultsHandler:. Limit will be set to no limit, and they will be sorted by startDate, in ascending order.

Parameters
sampleTypethe type of sample to read.
startDatethe starting limit for the query.
endDatethe end date.
resultsHandlerCalled when the query finishes executing. If unsuccessful, error contains information about what went wrong, otherwise it will be set to nil.

Provided by category BEHealthKit(read).

◆ readSamplesForWorkoutActivity:fromDate:toDate:resultsHandler:

- (void) readSamplesForWorkoutActivity: (HKWorkoutActivityType) activity
fromDate: (NSDate *) startDate
toDate: (NSDate *) endDate
resultsHandler: (void(^)(NSArray *results, NSError *error)) resultsHandler 

...

Parameters
activityThe activity type to read. See HKWorkoutActivityType documentation
startDatethe starting limit for the query.
endDatethe end date.
resultsHandlerCalled when the query finishes executing. If unsuccessful, error contains information about what went wrong, otherwise it will be set to nil.

Provided by category BEHealthKit(read).

◆ readStatisticsCollectionForQuantityType:predicate:options:anchorDate:intervalComponents:resultsHandler:

- (void) readStatisticsCollectionForQuantityType: (HKQuantityType *) quantityType
predicate: (NSPredicate *) predicate
options: (HKStatisticsOptions) options
anchorDate: (NSDate *) anchorDate
intervalComponents: (NSDateComponents *) interval
resultsHandler: (void(^)(id result, NSError *error)) resultsHandler 

A query that performs multiple statistics queries over a series of fixed-length time intervals, and returns the results. See HKStatisticsCollectionQuery

Parameters
quantityTypethe type of sample to read.
predicatea predicate that limits the results of the query
optionsa single option that defines the type of calculation to be performed on the data
anchorDatethe anchor date for the collection's time intervals
intervalthe date components that determine the time interval for each statistic in this collection
resultsHandlerCalled when the query finishes executing. If unsuccessful, error contains information about what went wrong, otherwise it will be set to nil.

Provided by category BEHealthKit(read).

◆ readStatisticsForQuantityType:predicate:options:resultsHandler:

- (void) readStatisticsForQuantityType: (HKQuantityType *) quantityType
predicate: (NSPredicate *) predicate
options: (HKStatisticsOptions) options
resultsHandler: (void(^)(id result, NSError *error)) resultsHandler 

A query that performs statistical calculations over a set of matching quantity samples, and returns the results. See HKStatisticsQuery.

Parameters
quantityTypethe type of sample to read.
predicatea predicate that limits the results of the query
optionsa single option that defines the type of calculation to be performed on the data
resultsHandlerCalled when the query finishes executing. If unsuccessful, error contains information about what went wrong, otherwise it will be set to nil.

Provided by category BEHealthKit(read).