Skip to content

Commit

Permalink
[LOOP-4622] Scenario loading without access to health (#564)
Browse files Browse the repository at this point in the history
* only clear cache when health kit access is denied

* use purge all dose entries
  • Loading branch information
nhamming authored May 5, 2023
1 parent d7deb46 commit 8f5e68d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,6 @@ extension DeviceDataManager: InsulinDeliveryStoreDelegate {
// MARK: - TestingPumpManager
extension DeviceDataManager {
func deleteTestingPumpData(completion: ((Error?) -> Void)? = nil) {

guard let testingPumpManager = pumpManager as? TestingPumpManager else {
completion?(nil)
return
Expand All @@ -1278,8 +1277,16 @@ extension DeviceDataManager {
return
}

healthStore.deleteObjects(of: self.doseStore.sampleType, predicate: devicePredicate) { success, deletedObjectCount, error in
if success {
guard !self.doseStore.sharingDenied else {
// only clear cache since access to health kit is denied
insulinDeliveryStore.purgeCachedInsulinDeliveryObjects() { error in
completion?(error)
}
return
}

insulinDeliveryStore.purgeAllDoseEntries(healthKitPredicate: devicePredicate) { error in
if error == nil {
insulinDeliveryStore.test_lastImmutableBasalEndDate = nil
}
completion?(error)
Expand All @@ -1288,11 +1295,18 @@ extension DeviceDataManager {
}

func deleteTestingCGMData(completion: ((Error?) -> Void)? = nil) {

guard let testingCGMManager = cgmManager as? TestingCGMManager else {
assertionFailure("\(#function) should be invoked only when a testing CGM manager is in use")
return
}

guard !glucoseStore.sharingDenied else {
// only clear cache since access to health kit is denied
glucoseStore.purgeCachedGlucoseObjects() { error in
completion?(error)
}
return
}

let predicate = HKQuery.predicateForObjects(from: [testingCGMManager.testingDevice])
glucoseStore.purgeAllGlucoseSamples(healthKitPredicate: predicate) { error in
Expand Down

0 comments on commit 8f5e68d

Please sign in to comment.