Posts

Post not yet marked as solved
1 Replies
0 Views
I also tried with:     func setUpBackgroundDelivery() async {         var queryDescriptors = [HKQueryDescriptor]()         for type in types {             queryDescriptors.append(HKQueryDescriptor(sampleType: type, predicate: nil))         }         let observerQuery = HKObserverQuery(queryDescriptors: queryDescriptors) { query, sampleTypesWithNewData, completionHandler, error in             if let error = error {                 self.logger.error("HKObserverQuery error: \(error.localizedDescription)")                 completionHandler()                 return             }             for type in sampleTypesWithNewData! {                 self.logger.debug("New \(type.debugDescription) data")                 self.anchoredQueryFor(sampleTypesWithNewData!)             }             completionHandler()         }         HKStore.execute(observerQuery)         for type in types {             do {                 try await HKStore.enableBackgroundDelivery(for: type, frequency: .hourly)             } catch {                 self.logger.error("setUpBackgroundDeliveryFor \(type) - error: \(error.localizedDescription)")             }         }     } And the update handler gets called twice: 2022-06-10 10:54:06.464318+0200 Cori[81627:9010600] [HealthKit] New HKQuantityTypeIdentifierBloodGlucose data 2022-06-10 10:54:06.467039+0200 Cori[81627:9010600] [HealthKit] New HKQuantityTypeIdentifierBloodGlucose data 2022-06-10 10:54:06.472524+0200 Cori[81627:9010601] [HealthKit] New data: [222 mg/dL 6AA78B15-4EB5-4F80-823E-DFBC43AB3C5A "Salud" (15.5), "iPhone14,2" (15.5)metadata: { 2022-06-10 10:54:06.472742+0200 Cori[81627:9010601] [HealthKit] 1 new HKQuantityTypeIdentifierBloodGlucose samples 2022-06-10 10:54:06.472889+0200 Cori[81627:9010591] [persistence] HealthKit: Start import to Core Data 2022-06-10 10:54:06.473032+0200 Cori[81627:9010591] [persistence] HealthKit: 1 samples of type HKQuantityTypeIdentifierBloodGlucose not from this app! 2022-06-10 10:54:06.473103+0200 Cori[81627:9010591] [persistence] HealthKit: Start batch insert request. 2022-06-10 10:54:06.473356+0200 Cori[81627:9010601] [HealthKit] New data: [222 mg/dL 6AA78B15-4EB5-4F80-823E-DFBC43AB3C5A "Salud" (15.5), "iPhone14,2" (15.5)metadata: { 2022-06-10 10:54:06.475530+0200 Cori[81627:9010591] [persistence] HealthKit: Successfully imported data. 2022-06-10 10:54:06.493688+0200 Cori[81627:9010601] [HealthKit] 1 new HKQuantityTypeIdentifierBloodGlucose samples 2022-06-10 10:54:06.493899+0200 Cori[81627:9010591] [persistence] HealthKit: Start import to Core Data 2022-06-10 10:54:06.494013+0200 Cori[81627:9010591] [persistence] HealthKit: 1 samples of type HKQuantityTypeIdentifierBloodGlucose not from this app! 2022-06-10 10:54:06.494057+0200 Cori[81627:9010591] [persistence] HealthKit: Start batch insert request. 2022-06-10 10:54:06.495381+0200 Cori[81627:9010601] [persistence] HealthKit: Successfully imported data.
Post not yet marked as solved
6 Replies
0 Views
I'm also having the same issues. Specially when the app is in background phase.