You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If the store is not available (for instance, iPad) return an error and don't go on.
if !HKHealthStore.isHealthDataAvailable() {
completion(false, MWError.custom(title: "HealthKit is not available in this Device"))
return;
}
// Request HealthKit authorization
healthKitStore.requestAuthorization(toShare: nil, read: getHealthTypesToRead()) { (success, error) in
DispatchQueue.main.async { // I'm executing this on mainthread because sometimes 'authorizeHealthKit' called on background thread and I need the completion block on main thread as the destination classes have some UI operations.
completion(success, error == nil ? nil : MWError.custom(default: error)) // On this completion block on the other classes, I will start fetching the HealthKit data.